home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / dev / gui / MPGui5xs.lha / sg / MPGui.c < prev    next >
C/C++ Source or Header  |  1997-03-04  |  135KB  |  4,591 lines

  1. // MPGui - requester library
  2. // Copyright (C) © 1995 Mark John Paddock
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mark@topic.demon.co.uk
  19. // mpaddock@cix.compulink.co.uk
  20.  
  21. /****** MPGui.library/--background-- ****************************************
  22. *
  23. * MPGui provides an easy way to display simple single colum requesters with
  24. * File/String/Number/Slider/Cycle/Check/ScreenMode/List gadgets.
  25. *
  26. * It uses a text input file to specify the format of the Gui.
  27. *
  28. * Menus can be provided.
  29. *
  30. * Bottom gadgets can be "Ok/Cancel" for normal gadgets or "Save/Use/Cancel"
  31. * for preferences requesters.
  32. * From Version 5.2 the short cuts for these buttons will automatically be
  33. * disabled if required. The library is also localised.
  34. *
  35. * From Version 5.4 opens locale.library(38) to work on OS3.0.
  36. *
  37. * Normal Help and continuous Help is supported.
  38. *
  39. * Keyboard shortcuts are supported.
  40. *
  41. * The format of the file is:
  42. *
  43. * * comment
  44. *                  Comment line
  45. *
  46. * Any #n# (n>=0) will be replaced by parameters if supplied
  47. * ## is changed to # if parameters are supplied
  48. * Some standard C conversions are done with \ values
  49. *  \\ -> \
  50. *  \" -> "
  51. *  \t -> tab
  52. *  \n -> newline
  53. *
  54. * "command "HelpMessage
  55. *        etc.      Command (etc. is ignored)
  56. *  "Comment"       Comment for heading of requester
  57. *  "HelpNode"      Global Help Node for requester
  58. *  GADGET "Title":"prefix"!HelpNode!HelpMessage!
  59. *                         A Gadget
  60. *                         GAGDET is type of gadget (see below).
  61. *                         "Title" is gadget title
  62. *                         "prefix" appears before the value in the result
  63. *                                  if prefix includes %s then result
  64. *                                  replaces %s instead
  65. *                         !HelpNode! is optional help string to
  66. *                                    use in call back
  67. *                         !HelpMessage is displayed in text gadget at top
  68. *
  69. *  LFILE "Title":"prefix":"def"!Help!
  70. *                  Input file string and request gadget
  71. *                  Key activates
  72. *                  Right shift and key shows requester
  73. *  SFILE "Title":"prefix":"def"!Help!
  74. *                  Output file string and gadget
  75. *                  Key activates
  76. *                  Right shift and key shows requester
  77. *  FILE "T":"P":"def"!Help!
  78. *                  File string and request (input file)
  79. *                  Key activates
  80. *                  Right shift and key shows requester
  81. *  OFILE "T":"P":"def":Y/N!Help!
  82. *                  Optional file (has checkbox)
  83. *                  Key toggles and activates if becomes selectable
  84. *                  Left shift and key activates if selectable
  85. *                  Right shift and key shows requester if selectable
  86. *  ONUMBER "T":"P":"def":Y/N!Help!
  87. *                  Optional number (has checkbox)
  88. *                  Key toggles and activates if becomes selectable
  89. *                  Left shift and key activates if selectable
  90. *  NUMBER "T":"P":"def"!Help!
  91. *                  Number
  92. *                  Key activates
  93. *  CYCLE "Title"!Help!
  94. *                  Cycle gadget, each entry can be followed by other gadgets
  95. *                  Key cycles
  96. *                  Shift and key cycles back
  97. *        "value1":"Prefix1"
  98. *        "value2":"Prefix2"
  99. *     gadgets      
  100. *                  Only active when item is 2
  101. *        "value3":"Prefix3"
  102. *  ENDCYCLE:"number or valuen" 
  103. *                  Finished by default value (numeric or string)
  104. *  STRING "Title":"prefix":"def"!Help!
  105. *                  String - use for floating point as well
  106. *                  Key activates
  107. *  OSTRING "Title":"prefix":"def":Y/N!Hlp!
  108. *                  String with checkbox
  109. *                  Key toggles and activates if becomes selectable
  110. *                  Left shift and key activates if selectable
  111. *  CHECK "T":"P":"NPrefix":Y/N!Help
  112. *                  Check box gadget
  113. *                  NPrefix (optional) used if Check not selected
  114. *                  Key toggles
  115. *  SLIDER "T":"P":"min":"max":"def"!Hlp!
  116. *                  Slider gadget
  117. *                  Key increases
  118. *                  Shift and key decreases
  119. *  MODEn "T":"P":"def"!Help!
  120. *                  Screen Mode requester
  121. *                  Key shows requester
  122. *                  n == 1 -> Workbench modes
  123. *                       2 -> Workbench modes + NONE
  124. *                       3 -> All modes
  125. *                       4 -> All modes + NONE (3 and 4 do not work too well)
  126. *  OMODEn "T":"P":"def":Y/N!Help!
  127. *                  Optional Screen Mode requester
  128. *                  Key toggles
  129. *                  Right shift and key shows requester if selectable
  130. *  FONTn "T":"P":"def"!Help!
  131. *                  Font requester
  132. *                  Key shows requester
  133. *                  n == 1 -> All Fonts
  134. *                       2 -> Fixed width only
  135. *  OFONTn "T":"P":"def":Y/N!Help!
  136. *                  Optional Font requester
  137. *                  Key toggles
  138. *                  Right shift and key shows requester if selectable
  139. *  LIST "Title":!Help!
  140. *                  List view
  141. *                  Key cycles
  142. *                  Shift and key cycles back
  143. *       "value1":"prefix1"
  144. *       "value2":"prefix2"
  145. *  ENDLIST:"number or valuen":"lines"
  146. *                  finished by default value and lines (optional) default 4
  147. *  MLIST "Title":!Help!
  148. *                  List view
  149. *                  Key cycles
  150. *                  Left shift and key cycles back
  151. *                  Right shift and key toggles selected
  152. *       "value1":"prefix1":"NPrefix1" (Negative Prefix optional)
  153. *       "value2":"prefix2"
  154. *  ENDMLIST:"values":"lines"
  155. *                  finished by default selected values (space seperated)
  156. *                  and lines (optional) default 4
  157. *  BUTTON "Title"  List of button gadgets - horizontal
  158. *                  If Title zero length then full width is used
  159. *       "Button text1":"n"!Help!HelpMessage!  n is number of button
  160. *       "Button text2":"m"!Help!HelpMessage!
  161. *  ENDBUTTON
  162. *  TEXT "Title":"def"Y/N!Help!HelpMessage!    (added in 5.1)
  163. *                  Text - If title 0 length then full width
  164. *                  Y to Center Text
  165. *  MTEXT "def"Y/N!Help!HelpMessage!    (added in 5.1)
  166. *                  Text without border
  167. *                  Y to Center Text
  168. *
  169. *****************************************************************************
  170. *
  171. */
  172.  
  173. #include <dos.h>
  174.  
  175. #define USE_BUILTIN_MATH
  176. #include <string.h>
  177. #include <stdlib.h>
  178. #include <math.h>
  179.  
  180. #include <stddef.h>
  181. #include <stdarg.h>
  182. #include <ctype.h>
  183.  
  184. #define INTUI_V36_NAMES_ONLY
  185. #define INTUITION_IOBSOLETE_H
  186. #define ASL_V38_NAMES_ONLY
  187. #include <graphics/gfxbase.h>
  188. #include <proto/exec.h>
  189. #include <proto/gadtools.h>
  190. #include <proto/intuition.h>
  191. #include <proto/graphics.h>
  192. #include <proto/asl.h>
  193. #include <proto/dos.h>
  194. #include <proto/utility.h>
  195. #include <proto/locale.h>
  196.  
  197. #include <intuition/gadgetclass.h>
  198. #include <dos/dostags.h>
  199. #include <exec/memory.h>
  200.  
  201. extern long __oslibversion=39;
  202.  
  203. extern struct Catalog *Catalog=NULL;
  204.  
  205. #define CATCOMP_BLOCK
  206. #define CATCOMP_NUMBERS
  207. #include "messages.h"
  208.  
  209. #include "MPGui.h"
  210. #include "libraries/MPGui.h"
  211.  
  212. const char Version[]="$VER: MPGui.library 5.5 (4.3.97)";
  213.  
  214. struct MPGuiHandle * __asm __saveds AllocMPGuiHandleA(register __a0 struct TagItem * TagList);
  215. void __asm __saveds FreeMPGuiHandle(register __a0 struct MPGuiHandle * );
  216. char * __asm __saveds MPGuiError(register __a0 struct MPGuiHandle * );
  217. char * __asm __saveds SyncMPGuiRequest(register __a0 char * , register __a1 struct MPGuiHandle * );
  218. __saveds __asm ULONG MPGuiResponse(register __a0 struct MPGuiHandle *gh);
  219. __saveds __asm BOOL SetMPGuiGadgetValue(register __a0 struct MPGuiHandle *gh,
  220.                             register __a1 char *Title, register __a2 char *Value);
  221. __saveds __asm char *MPGuiCurrentAttrs(register __a0 struct MPGuiHandle *gh);
  222. void __saveds __asm RefreshMPGui(register __a0 struct MPGuiHandle *gh);
  223. struct Window * __saveds __asm MPGuiWindow(register __a0 struct MPGuiHandle *gh);
  224.  
  225. /* Internal prototypes */
  226. int sprintf(unsigned char * ,const unsigned char * , ...);
  227. unsigned char * mystrdup(struct MPGuiHandle * , unsigned char * );
  228. void Command(struct MPGuiHandle * );
  229. void pError(struct MPGuiHandle * , unsigned char const * , unsigned char * );
  230. unsigned char * myfgets(struct MPGuiHandle * );
  231. void ProcessGadget(struct MPGuiHandle * );
  232. void ProcessButton(struct MPGuiHandle * );
  233. void ProcessCycle(struct MPGuiHandle * );
  234. void ProcessList(struct MPGuiHandle * );
  235. void ProcessMList(struct MPGuiHandle * );
  236. void GetTitle(BOOL SetLeft,struct MPGuiHandle * );
  237. void GetParameter(struct MPGuiHandle * );
  238. void GetNParameter(struct MPGuiHandle * );
  239. void GetStringDefault(struct MPGuiHandle * );
  240. void GetNumberDefault(struct MPGuiHandle * );
  241. void GetCheckDefault(struct MPGuiHandle * );
  242. void GetDefCycle(struct MPGuiHandle * );
  243. void GetDefList(struct MPGuiHandle * );
  244. void GetDefMList(struct MPGuiHandle * );
  245. void GetDefLines(struct MPGuiHandle * );
  246. void GetCycleTitle(struct MPGuiHandle * );
  247. void GetCycleParameter(struct MPGuiHandle * );
  248. void GetListTitle(struct MPGuiHandle * );
  249. void GetListParameter(struct MPGuiHandle * );
  250. void GetListNParameter(struct MPGuiHandle * );
  251. unsigned char * SkipSpace(unsigned char * );
  252. void RequesterStuff(struct MPGuiHandle *);
  253. BOOL CreateGadgets(struct MPGuiHandle *);
  254. static void checkleft(struct MPGuiHandle *gh, int addheight, short *curgh, int *tleft);
  255. BOOL GetAFile(struct MPGuiHandle * , UBYTE const * , unsigned char const * , ULONG ,char *);
  256. BOOL GetAMode(struct MPGuiHandle *, struct MyGadget * , UBYTE const * , unsigned char const *);
  257. BOOL GetAFont(struct MPGuiHandle *, struct MyGadget * , UBYTE const * , unsigned char const *);
  258. void GetHelp(struct MPGuiHandle * );
  259. void DisableWindow(struct MPGuiHandle *gh);
  260. void EnableWindow(struct MPGuiHandle *gh);
  261. ULONG MyCallHookPkt(struct MPGuiHandle *gh,struct Hook *,APTR,APTR);
  262. ULONG __asm MyRefresh(register __a0 struct Hook *hook,
  263.                                   register __a2 struct FileRequester *fr,
  264.                                   register __a1 struct IntuiMessage *msg);
  265.  
  266.  
  267. /****** MPGui.library/AllocMPGuiHandleA *************************************
  268. *
  269. *   NAME   
  270. *  AllocMPGuiHandleA -- Allocates an MPGuiHandle. (V3)
  271. *  AllocMPGuiHandle -- Varargs version of AllocMPGuiHandleA (V3)
  272. *
  273. *   SYNOPSIS
  274. *  gh = AllocMPGuiHandleA(taglist)
  275. *  D0                     A0
  276. *
  277. *  struct MPGuiHandle * AllocMPGuiHandleA(struct TagItem *);
  278. *
  279. *  gh = AllocMPGuiHandle(Tag1, ...)
  280. *
  281. *  struct MPGuiHandle * AllocMPGuiHandle(ULONG,...);
  282. *
  283. *   FUNCTION
  284. *  Allocates an MPGuiHandle.
  285. *
  286. *   INPUTS
  287. *  taglist - pointer to TagItem array.
  288. *
  289. *  Tags are:
  290. *
  291. *  MPG_PUBSCREENNAME - Data is char * name of public screen to use.
  292. *                      Default is default public screen.
  293. *  MPG_RELMOUSE      - Data is BOOL. TURE to open requester near pointer.
  294. *                      Default is FALSE.
  295. *  MPG_HELP          - Data is struct Hook *, called with object=char * to
  296. *                      help node to be displayed.
  297. *  MPG_CHELP         - Call help when gadget changes
  298. *  MPG_PARAMS        - Data is char ** array of parameters
  299. *  MPG_NEWLINE       - Data is BOOL. TRUE means new line rather than space
  300. *                      in output, no "s round files or screen modes.
  301. *                      Default is FALSE.
  302. *  MPG_PREFS         - Data is BOOL. Default FALSE. TRUE provides
  303. *                      _Save/_Use/_Cancel gadgets, Use MPGuiResponse() to
  304. *                      get response (1=Save 2=Use), Esc key will not exit.
  305. *  MPG_MENUS         - Data is struct NewMenu *.
  306. *  MPG_MENUHOOK      - Data is struct Hook *, called with
  307. *                      object=struct IntuiMsg *, message = struct Menu *
  308. *                      If MPG_HELP is set then called for MENUHELP as well.
  309. *                      Return 0 to quit, non 0 to continue.
  310. *  MPG_SIGNALS       - Data is ULONG signals to wait for then call hook
  311. *                      provided in MPG_SIGNALHOOK.
  312. *  MPG_SIGNALHOOK    - Data is struct Hook *, called with
  313. *                      object = ULONG signals received,
  314. *                      message = ULONG notused
  315. *                      Return 0 to quit, non 0 to continue.
  316. *  MPG_CHECKMARK     - Data is struct Image * for menu checkmark
  317. *  MPG_AMIGAKEY      - Data is struct Image * for menu AmigaKey
  318. *  MPG_BUTTONHOOK        - Data is struct Hook *,
  319. *                      called with object=struct MPGuiHandle *,
  320. *                      message = number of button
  321. *                      Return 0 to quit, non 0 to continue.
  322. *  MPG_NOBUTTONS     - If set then no buttons are shown, overrides MPG_PREFS.
  323. *
  324. *   RESULT
  325. *  gh - Allocated MPGuiHandle.
  326. *       NULL on error (no memory).
  327. *
  328. *   EXAMPLE
  329. *
  330. *   NOTES
  331. *
  332. *   BUGS
  333. *  The allocated handle has a max size of about 3K for the response.
  334. *  The maximum parameter replaced line length is about 2K.
  335. *  FONT? gadgets ignore the size at the moment.
  336. *  If there are more than 3 BUTTON gadgets in a row then they are left
  337. *  justified - should be fully justified.
  338. *  Button layout may not yet be correct.
  339. *
  340. *   SEE ALSO
  341. *  FreeMPGuiHandle(),MPGuiResponse().
  342. *
  343. *****************************************************************************
  344. *
  345. */
  346. // Allocate a handle
  347. struct MPGuiHandle *__saveds __asm
  348. AllocMPGuiHandleA(register __a0 struct TagItem *TagList) {
  349.     struct MPGuiHandle *gh;
  350.  
  351.     if (gh = (struct MPGuiHandle *)AllocMem(sizeof(struct MPGuiHandle),MEMF_ANY | MEMF_CLEAR)) {
  352.         gh->TagList = CloneTagItems(TagList);
  353.         if (gh->MemPool = CreatePool(MEMF_CLEAR | MEMF_ANY,2048,1024)) {
  354.             if (gh->filereq = AllocFileRequest()) {
  355.                 gh->RefreshHook.h_Entry = (HOOKFUNC)MyRefresh;
  356.                 gh->RefreshHook.h_Data = gh;
  357.                 return gh;
  358.             }
  359.             DeletePool(gh->MemPool);
  360.         }
  361.         FreeMem(gh,sizeof(struct MPGuiHandle));
  362.     }
  363.     return NULL;
  364. }
  365.  
  366. /****** MPGui.library/FreeMPGuiHandle ****************************************
  367. *
  368. *   NAME   
  369. *  FreeMPGuiHandle -- Frees a Handle allocated by AllocMPGuiHandleA(). (V3)
  370. *
  371. *   SYNOPSIS
  372. *  FreeMPGuiHandle( gh)
  373. *                   A0
  374. *
  375. *  void FreeMPGuiHandle( struct MPGuiHandle *);
  376. *
  377. *
  378. *   FUNCTION
  379. *  Frees a Handle allocated by AllocMPGuiHandleA().
  380. *
  381. *   INPUTS
  382. *  gh - Handle allocated by AllocMPGuiHandleA.
  383. *
  384. *   RESULT
  385. *  None.
  386. *
  387. *   EXAMPLE
  388. *
  389. *   NOTES
  390. *
  391. *   BUGS
  392. *
  393. *   SEE ALSO
  394. *  AllocMPGuiHandleA().
  395. *
  396. *****************************************************************************
  397. *
  398. */
  399. // Free a handle
  400. __saveds __asm void
  401. FreeMPGuiHandle(register __a0 struct MPGuiHandle *gh) {
  402.     if (gh) {
  403.         if (gh->TagList) {
  404.             FreeTagItems(gh->TagList);
  405.         }
  406.         if (gh->filereq) {
  407.             FreeAslRequest(gh->filereq);
  408.         }
  409.         if (gh->MemPool) {
  410.             DeletePool(gh->MemPool);
  411.         }
  412.         FreeMem(gh,sizeof(struct MPGuiHandle));
  413.     }
  414. }
  415.     
  416. /****** MPGui.library/MPGuiError *********************************************
  417. *
  418. *   NAME   
  419. *  MPGuiError -- Returns the error message for an MPGuiHandle. (V3)
  420. *
  421. *   SYNOPSIS
  422. *  Message = MPGuiError(gh )
  423. *  D0                   A0
  424. *
  425. *  char * MPGuiError( struct MPGuiHandle *);
  426. *
  427. *   FUNCTION
  428. *  Returns the error message for an MPGuiHandle.
  429. *
  430. *   INPUTS
  431. *  gh - MPGuiHandle allocated by AllocMPGuiHandleA().
  432. *
  433. *   RESULT
  434. *  Message - The text of an error message. May be multi line.
  435. *
  436. *   EXAMPLE
  437. *
  438. *   NOTES
  439. *  Use after SyncMPGuiRequest() returns -1.
  440. *
  441. *   BUGS
  442. *
  443. *   SEE ALSO
  444. *  SyncMPGuiRequest().
  445. *
  446. ******************************************************************************
  447. *
  448. */
  449. __saveds __asm char *
  450. MPGuiError(register __a0 struct MPGuiHandle *gh) {
  451.     return gh->error;
  452. }
  453.  
  454. /****** MPGui.library/MPGuiResponse ******************************************
  455. *
  456. *   NAME   
  457. *  MPGuiResponse -- returns the response from a Prefs MPGui. (V3)
  458. *
  459. *   SYNOPSIS
  460. *  resp = MPGuiResponse( gh)
  461. *  D0                   A0
  462. *
  463. *  ULONG MPGuiResponse( struct MPGuiHandle *);
  464. *
  465. *   FUNCTION
  466. *  Returns the response after calling SyncMPGuiRequest() with MPG_PREFS.
  467. *
  468. *   INPUTS
  469. *  gh - An MPGuiHandle.
  470. *
  471. *   RESULT
  472. *  resp - MPG_SAVE Save gadget was pressed.
  473. *         MPG_USE  Use gadget was pressed.
  474. *
  475. *   EXAMPLE
  476. *
  477. *   NOTES
  478. *  Only use if SyncMPGui() returns not (0 or -1).
  479. *
  480. *   BUGS
  481. *
  482. *   SEE ALSO
  483. *  AllocMPGuiHandleA(),SyncMPGuiRequest().
  484. *
  485. *****************************************************************************
  486. *
  487. */
  488. __saveds __asm ULONG
  489. MPGuiResponse(register __a0 struct MPGuiHandle *gh) {
  490.     return gh->Response;
  491. }
  492.  
  493. /****** MPGui.library/MPGuiCurrentAttrs *************************************
  494. *
  495. *   NAME   
  496. *  MPGuiCurrentAttrs -- Returns the Current MPGui attributes. (V3)
  497. *
  498. *   SYNOPSIS
  499. *  Attrs = MPGuiCurrentAttrs( gh)
  500. *  D0                          A0
  501. *
  502. *  char * MPGuiCurrentAttrs( struct MPGuiHandle *);
  503. *
  504. *   FUNCTION
  505. *  Returns the same as would be returned by SyncMPGuiRequest if the OK gadget
  506. *  is pressed now.
  507. *
  508. *   INPUTS
  509. *  gh - An MPGuiHandle currently being used by SyncMPGuiRequest().
  510. *
  511. *   RESULT
  512. *  Attrs - String that would be returned SyncMPGuiRequest.
  513. *
  514. *   EXAMPLE
  515. *
  516. *   NOTES
  517. *  This should be called from a MPG_MENUHOOK supplied to AllocMPGuiHandle().
  518. *  e.g. If a Save As... menu item is called.
  519. *
  520. *   BUGS
  521. *
  522. *   SEE ALSO
  523. *  SyncMPGuiRequest().
  524. *
  525. *****************************************************************************
  526. *
  527. */
  528. __saveds __asm char *
  529. MPGuiCurrentAttrs(register __a0 struct MPGuiHandle *gh) {
  530.     struct MyGadget *LoopGadget;
  531.     int count;
  532.     struct MyValue *MyValue;
  533.     char *p = NULL;
  534.     ULONG l = 0;
  535.     char buffer[32];
  536.  
  537.     sprintf(gh->result,"%s",gh->Command);
  538.     if (gh->NewLine) {
  539.         strcat(gh->result,"\n");
  540.     }
  541.     for (LoopGadget = (struct MyGadget *)(gh->GList.lh_Head);
  542.             LoopGadget->GNode.ln_Succ;
  543.             LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)) {
  544.         if (!LoopGadget->OwnCycle || (LoopGadget->OwnCycle->Currenty == LoopGadget->Activey)) {
  545.             switch (LoopGadget->Type) {
  546.             case GAD_FILE:
  547.             case GAD_LFILE:
  548.             case GAD_SFILE:
  549.                 GT_GetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  550.                                     GTST_String,&p,
  551.                                     TAG_END);
  552.                 if (strstr(LoopGadget->Prefix,"%s")) {
  553.                     sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  554.                 }
  555.                 else {
  556.                     if (gh->NewLine) {
  557.                         sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  558.                     }
  559.                     else {
  560.                         sprintf(gh->tBuffer,"%s\"%s\"",LoopGadget->Prefix,p);
  561.                     }
  562.                 }
  563.                 strcat(gh->result,gh->tBuffer);
  564.                 break;
  565.             case GAD_MODE:
  566.             case GAD_FONT:
  567.                 GT_GetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  568.                                     GTTX_Text,&p,
  569.                                     TAG_END);
  570.                 if (strstr(LoopGadget->Prefix,"%s")) {
  571.                     sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  572.                 }
  573.                 else {
  574.                     if (gh->NewLine) {
  575.                         sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  576.                     }
  577.                     else {
  578.                         sprintf(gh->tBuffer,"%s\"%s\"",LoopGadget->Prefix,p);
  579.                     }
  580.                 }
  581.                 strcat(gh->result,gh->tBuffer);
  582.                 break;
  583.             case GAD_OMODE:
  584.             case GAD_OFONT:
  585.                 if (LoopGadget->Currentc) {
  586.                     GT_GetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  587.                                         GTTX_Text,&p,
  588.                                         TAG_END);
  589.                     if (strstr(LoopGadget->Prefix,"%s")) {
  590.                         sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  591.                     }
  592.                     else {
  593.                         if (gh->NewLine) {
  594.                             sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  595.                         }
  596.                         else {
  597.                             sprintf(gh->tBuffer,"%s\"%s\"",LoopGadget->Prefix,p);
  598.                         }
  599.                     }
  600.                     strcat(gh->result,gh->tBuffer);
  601.                 }
  602.                 break;
  603.             case GAD_OFILE:
  604.                 if (LoopGadget->Currentc) {
  605.                     GT_GetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  606.                                         GTST_String,&p,
  607.                                         TAG_END);
  608.                     if (strstr(LoopGadget->Prefix,"%s")) {
  609.                         sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  610.                     }
  611.                     else {
  612.                         if (gh->NewLine) {
  613.                             sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  614.                         }
  615.                         else {
  616.                             sprintf(gh->tBuffer,"%s\"%s\"",LoopGadget->Prefix,p);
  617.                         }
  618.                     }
  619.                     strcat(gh->result,gh->tBuffer);
  620.                 }
  621.                 break;
  622.             case GAD_ONUMBER:
  623.                 if (LoopGadget->Currentc) {
  624.                     GT_GetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  625.                                     GTIN_Number,&l,
  626.                                     TAG_END);
  627.                     if (strstr(LoopGadget->Prefix,"%s")) {
  628.                         sprintf(buffer,"%ld",l);
  629.                         sprintf(gh->tBuffer,LoopGadget->Prefix,buffer);
  630.                     }
  631.                     else {
  632.                         sprintf(gh->tBuffer,"%s%ld",LoopGadget->Prefix,l);
  633.                     }
  634.                     strcat(gh->result,gh->tBuffer);
  635.                 }
  636.                 break;
  637.             case GAD_NUMBER:
  638.                 GT_GetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  639.                                 GTIN_Number,&l,
  640.                                 TAG_END);
  641.                 if (strstr(LoopGadget->Prefix,"%s")) {
  642.                     sprintf(buffer,"%ld",l);
  643.                     sprintf(gh->tBuffer,LoopGadget->Prefix,buffer);
  644.                 }
  645.                 else {
  646.                     sprintf(gh->tBuffer,"%s%ld",LoopGadget->Prefix,l);
  647.                 }
  648.                 strcat(gh->result,gh->tBuffer);
  649.                 break;
  650.             case GAD_CYCLE:
  651.             case GAD_LIST:
  652.                 count = 0;
  653.                 for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
  654.                         MyValue->VNode.ln_Succ;
  655.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  656.                     if (count == LoopGadget->Currenty) {
  657.                         strcat(gh->result,MyValue->Prefix);
  658.                     }
  659.                     ++count;
  660.                 }
  661.                 break;
  662.             case GAD_MLIST:
  663.                 for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
  664.                         MyValue->VNode.ln_Succ;
  665.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  666.                     if (MyValue->Selected) {
  667.                         strcat(gh->result,MyValue->Prefix);
  668.                         if (gh->NewLine) {
  669.                             strcat(gh->result,"\n");
  670.                         }
  671.                         else {
  672.                             strcat(gh->result," ");
  673.                         }
  674.                     }
  675.                     else {
  676.                         if (MyValue->NPrefix) {
  677.                             strcat(gh->result,MyValue->NPrefix);
  678.                             if (gh->NewLine) {
  679.                                 strcat(gh->result,"\n");
  680.                             }
  681.                             else {
  682.                                 strcat(gh->result," ");
  683.                             }
  684.                         }
  685.                     }
  686.                 }
  687.                 break;
  688.             case GAD_STRING:
  689.                 GT_GetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  690.                                     GTST_String,&p,
  691.                                     TAG_END);
  692.                 if (strstr(LoopGadget->Prefix,"%s")) {
  693.                     sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  694.                 }
  695.                 else {
  696.                     sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  697.                 }
  698.                 strcat(gh->result,gh->tBuffer);
  699.                 break;
  700.             case GAD_OSTRING:
  701.                 if (LoopGadget->Currentc) {
  702.                     GT_GetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  703.                                         GTST_String,&p,
  704.                                         TAG_END);
  705.                     if (strstr(LoopGadget->Prefix,"%s")) {
  706.                         sprintf(gh->tBuffer,LoopGadget->Prefix,p);
  707.                     }
  708.                     else {
  709.                         sprintf(gh->tBuffer,"%s%s",LoopGadget->Prefix,p);
  710.                     }
  711.                     strcat(gh->result,gh->tBuffer);
  712.                 }
  713.                 break;
  714.             case GAD_CHECK:
  715.                 if (LoopGadget->Currentc) {
  716.                     strcat(gh->result,LoopGadget->Prefix);
  717.                 }
  718.                 else {
  719.                     if (LoopGadget->NPrefix) {
  720.                         strcat(gh->result,LoopGadget->NPrefix);
  721.                     }
  722.                 }
  723.                 break;
  724.             case GAD_SLIDER:
  725.                 if (strstr(LoopGadget->Prefix,"%s")) {
  726.                     sprintf(buffer,"%ld",LoopGadget->Currentn);
  727.                     sprintf(gh->tBuffer,LoopGadget->Prefix,buffer);
  728.                 }
  729.                 else {
  730.                     sprintf(gh->tBuffer,"%s%ld",LoopGadget->Prefix,LoopGadget->Currentn);
  731.                 }
  732.                 strcat(gh->result,gh->tBuffer);
  733.                 break;
  734.             case GAD_BUTTON:
  735.                 break;
  736.             case GAD_BUTTONTEXT:
  737.                 break;
  738.             }
  739.             if (gh->NewLine) {
  740.                 strcat(gh->result,"\n");
  741.             }
  742.             else {
  743.                 strcat(gh->result," ");
  744.             }
  745.         }
  746.     }
  747.     // convert " back
  748.     p = gh->result;
  749.     while (*p) {
  750.         if ('\001' == *p) {
  751.             *p = '"';
  752.         }
  753.         ++p;
  754.     }
  755.     return gh->result;
  756. }
  757.  
  758. /****** MPGui.library/SetMPGuiGadgetValue ***********************************
  759. *
  760. *   NAME   
  761. *  SetMPGuiGadgetValue -- Sets the value of an MPGui gadget. (V3)
  762. *
  763. *   SYNOPSIS
  764. *  succ = SetMPGuiGadgetValue( gh, Title, Value)
  765. *  D0                          A0  A1     A2
  766. *
  767. *  BOOL SetMPGuiGadgetValue( struct MPGuiHandle *, char *, char *);
  768. *
  769. *   FUNCTION
  770. *  Sets the value of a gadget currently being displayed by
  771. *  SyncMPGuiRequest().
  772. *
  773. *   INPUTS
  774. *  gh    - MPGuiHandle being displayed by SyncMPGuiRequest().
  775. *  Title - Title of the gadget as in the input file.
  776. *  Value - Value of the gadget.
  777. *          Y/N for a CHECKs.
  778. *          A String for Strings/Files/Modes.
  779. *          A String (which is converted using strtol) for Numbers/Sliders.
  780. *          A value or number in the list/cycle for lists/cycles.
  781. *          Values strung together sperated by space for an MLIST gadget
  782. *
  783. *   RESULT
  784. *  error - 1 for success, 0 for failure.
  785. *          Error means gadget not found or Value not found.
  786. *
  787. *   EXAMPLE
  788. *
  789. *   NOTES
  790. *  Title must be exact including "_" as required.
  791. *
  792. *  This should be called from a MPG_MENUHOOK supplied to AllocMPGuiHandle().
  793. *  e.g. If a Reset To Defaults... menu item is called.
  794. *
  795. *  BUTTON gadgets can not have there attributes set.
  796. *
  797. *   BUGS
  798. *  For an MLIST gadget if a value is a substring of another gadget then the
  799. *  value can be incorrectly set.
  800. *
  801. *  MTEXT/TEXT gadgets can not be updated.
  802. *
  803. *   SEE ALSO
  804. *  SyncMPGuiRequest().
  805. *
  806. *****************************************************************************
  807. *
  808. */
  809. __saveds __asm BOOL
  810. SetMPGuiGadgetValue(register __a0 struct MPGuiHandle *gh,
  811.                             register __a1 char *Title, register __a2 char *Value) {
  812.     struct MyGadget *LoopGadget,*Loop1Gadget;
  813.     BOOL Ok = FALSE;
  814.     int i;
  815.     int number;
  816.     struct MyValue *MyValue;
  817.     char *s;
  818.  
  819.     for (LoopGadget = (struct MyGadget *)(gh->GList.lh_Head);
  820.                                         LoopGadget->GNode.ln_Succ;
  821.                                         LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)) {
  822.         if (!strcmp(LoopGadget->Title,Title)) {
  823.             switch (LoopGadget->Type) {
  824.             case GAD_LFILE:
  825.             case GAD_SFILE:
  826.             case GAD_FILE:
  827.             case GAD_STRING:
  828.                 Ok = TRUE;
  829.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  830.                                     GTST_String,Value,
  831.                                     TAG_END);
  832.                 break;
  833.             case GAD_MODE:
  834.             case GAD_FONT:
  835.                 Ok = TRUE;
  836.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  837.                                     GTTX_Text,Value,
  838.                                     TAG_END);
  839.                 break;
  840.             case GAD_OMODE:
  841.             case GAD_OFONT:
  842.                 Ok = TRUE;
  843.                 GT_SetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  844.                                     GTTX_Text,Value,
  845.                                     TAG_END);
  846.                 break;
  847.             case GAD_NUMBER:
  848.                 Ok = TRUE;
  849.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  850.                                     GTIN_Number,strtol(Value,NULL,10),
  851.                                     TAG_END);
  852.                 break;
  853.             case GAD_ONUMBER:
  854.                 Ok = TRUE;
  855.                 GT_SetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  856.                                     GTIN_Number,strtol(Value,NULL,10),
  857.                                     TAG_END);
  858.                 break;
  859.             case GAD_CYCLE:
  860.                 i = 0;
  861.                 number = -1;
  862.                 for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
  863.                         MyValue->VNode.ln_Succ;
  864.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  865.                     if (!strcmp(Value,MyValue->VNode.ln_Name)) {
  866.                         number = i;
  867.                     }
  868.                     ++i;
  869.                 }
  870.                 if (number == -1) {
  871.                     number = strtol(Value,NULL,10);
  872.                 }
  873.                 if (number != -1) {
  874.                     Ok = TRUE;
  875.                     LoopGadget->Currenty = number;
  876.                     GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  877.                                 GTCY_Active, LoopGadget->Currenty,
  878.                                 TAG_END);
  879.                     for (Loop1Gadget = (struct MyGadget *)(gh->GList.lh_Head);
  880.                             Loop1Gadget->GNode.ln_Succ;
  881.                             Loop1Gadget = (struct MyGadget *)(Loop1Gadget->GNode.ln_Succ)){
  882.                         if (LoopGadget == Loop1Gadget->OwnCycle) {
  883.                             GT_SetGadgetAttrs(Loop1Gadget->Gadget1,gh->Window,NULL,
  884.                                                     GA_Disabled,LoopGadget->Currenty != Loop1Gadget->Activey,
  885.                                                     TAG_END);
  886.                             if (Loop1Gadget->Gadget2) {
  887.                                 GT_SetGadgetAttrs(Loop1Gadget->Gadget2,gh->Window,NULL,
  888.                                         GA_Disabled,(LoopGadget->Currenty != Loop1Gadget->Activey) ||
  889.                                                         (((Loop1Gadget->Type == GAD_ONUMBER) ||
  890.                                                           (Loop1Gadget->Type == GAD_OSTRING) ||
  891.                                                           (Loop1Gadget->Type == GAD_OFILE)) && (!Loop1Gadget->Currentc)),
  892.                                         TAG_END);
  893.                             }
  894.                             if (Loop1Gadget->Gadget3) {
  895.                                 GT_SetGadgetAttrs(Loop1Gadget->Gadget3,gh->Window,NULL,
  896.                                         GA_Disabled,(LoopGadget->Currenty != Loop1Gadget->Activey) ||
  897.                                                           (((Loop1Gadget->Type == GAD_OFILE) ||
  898.                                                             (Loop1Gadget->Type == GAD_OMODE) ||
  899.                                                             (Loop1Gadget->Type == GAD_OFONT))
  900.                                                             && (!Loop1Gadget->Currentc)),
  901.                                         TAG_END);
  902.                             }
  903.                         }
  904.                     }
  905.                 }
  906.                 break;
  907.             case GAD_LIST:
  908.                 i = 0;
  909.                 number = -1;
  910.                 for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
  911.                         MyValue->VNode.ln_Succ;
  912.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  913.                     if (!strcmp(Value,MyValue->VNode.ln_Name)) {
  914.                         number = i;
  915.                     }
  916.                     ++i;
  917.                 }
  918.                 if (number == -1) {
  919.                     number = strtol(Value,NULL,10);
  920.                 }
  921.                 if (number != -1) {
  922.                     Ok = TRUE;
  923.                     LoopGadget->Currenty = number;
  924.                     GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  925.                                 GTLV_Selected, LoopGadget->Currenty,
  926.                                 GTLV_MakeVisible, LoopGadget->Currenty,
  927.                                 TAG_END);
  928.                 }
  929.                 break;
  930.             case GAD_MLIST:
  931.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  932.                                     GTLV_Labels, -1,
  933.                                     TAG_END);
  934.                 for (MyValue = (struct MyValue *)(LoopGadget->VList.lh_Head);
  935.                         MyValue->VNode.ln_Succ;
  936.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)) {
  937.                     if (s = strstr(Value,MyValue->VNode.ln_Name)) {
  938.                         MyValue->Selected = TRUE;
  939.                     }
  940.                     else {
  941.                         MyValue->Selected = FALSE;
  942.                     }
  943.                 }
  944.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  945.                                     GTLV_Labels, &(LoopGadget->VList),
  946.                                     TAG_END);
  947.                 break;
  948.             case GAD_OFILE:
  949.             case GAD_OSTRING:
  950.                 Ok = TRUE;
  951.                 GT_SetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  952.                                     GTST_String,Value,
  953.                                     TAG_END);
  954.                 break;
  955.             case GAD_CHECK:
  956.                 Ok = TRUE;
  957.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  958.                                     GTCB_Checked, LoopGadget->Currentc = (toupper(*Value) == 'Y'),
  959.                                     TAG_END);
  960.                 break;
  961.             case GAD_SLIDER:
  962.                 Ok = TRUE;
  963.                 LoopGadget->Currentn = strtol(Value,NULL,10);
  964.                 GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  965.                                 GTSL_Level, LoopGadget->Currentn,
  966.                                 TAG_END);
  967.                 break;
  968.             case GAD_BUTTON:
  969.                 break;
  970.             case GAD_BUTTONTEXT:
  971.                 break;
  972.             default:
  973.                 break;
  974.             }
  975.         }
  976.     }
  977.     return Ok;
  978. }
  979.  
  980. /****** MPGui.library/SyncMPGuiRequest **************************************
  981. *
  982. *   NAME   
  983. *  SyncMPGuiRequest -- Displays and processes an MPGui. (V3)
  984. *
  985. *   SYNOPSIS
  986. *  result = SyncMPGuiRequest( fname, gh)
  987. *  D0                         A0     A1
  988. *
  989. *  char * SyncMPGuiRequest( char *, struct MPGuiHandle *);
  990. *
  991. *   FUNCTION
  992. *  Displays an MPGuiHandle allocated by AllocMPGuiHandle() and processes all
  993. *  messages.
  994. *
  995. *   INPUTS
  996. *  fname - name of file describing gui.
  997. *  gh    - MPGuiHandle allocated by AllocMPGuiHandle().
  998. *
  999. *   RESULT
  1000. *  Attributes of the MPGui if Save/Use/Ok was used.
  1001. *  0 if Cancel was used/window closed/Esc pressed.
  1002. *  -1 for error. Use MPGuiError() to get error.
  1003. *
  1004. *   EXAMPLE
  1005. *
  1006. *   NOTES
  1007. *  If MPG_PREFS was supplied to AllocMPGuiHandle() then use MPGuiResponse()
  1008. *  to determine if Save or Use was pressed.
  1009. *
  1010. *  If the requester will not fit in one column with the default screen font
  1011. *  then it falls back in the following order until it fits:
  1012. *
  1013. *    Compressed vertical seperation;
  1014. *    Default fixed font;
  1015. *    Default fixed font with compressed vertical seperation;
  1016. *    Topaz 80;
  1017. *    Topaz 80 with compressed vertical seperation;
  1018. *    Two columns topaz 80 with compressed vertical seperation;
  1019. *    3 or more columns topaz 80 with compressed vertical seperation.
  1020. *
  1021. *   BUGS
  1022. *  When trying to cope with very small screens/very large requesters it can
  1023. *  result in gadgets with negative width which can crash the system. This
  1024. *  should only happen if more than 2 columns are required.
  1025. *
  1026. *  Fixed in version 5.1 Buttons with no Title going to a new column
  1027. *
  1028. *   SEE ALSO
  1029. *  AllocMPGuiHandleA(),MPGuiError(),MPGuiResponse().
  1030. *
  1031. *****************************************************************************
  1032. *
  1033. */
  1034. char * __saveds __asm
  1035. SyncMPGuiRequest(register __a0 char *fname,register __a1 struct MPGuiHandle *gh) {
  1036.     UBYTE *temp = 0;
  1037.     struct TagItem *ti;
  1038.     if (!fname || !gh) {
  1039.         pError(gh,GetMessage(MSG_ERR_NOPS),NULL);
  1040.         return (char *) -1;
  1041.     }
  1042.     if (ti = FindTagItem(MPG_AMIGAKEY,gh->TagList)) {
  1043.         gh->Amiga = (struct Image *)ti->ti_Data;
  1044.     }
  1045.     if (ti = FindTagItem(MPG_CHECKMARK,gh->TagList)) {
  1046.         gh->Check = (struct Image *)ti->ti_Data;
  1047.     }
  1048.     if (ti = FindTagItem(MPG_PUBSCREENNAME,gh->TagList)) {
  1049.         temp = (UBYTE *)(ti->ti_Data);
  1050.     }
  1051.     if (!(gh->MyScreen = LockPubScreen(temp))) {
  1052.         gh->MyScreen = LockPubScreen(NULL);
  1053.     }
  1054.     if (ti = FindTagItem(MPG_HELP,gh->TagList)) {
  1055.         gh->HelpFunc = (struct Hook *)(ti->ti_Data);
  1056.     }
  1057.     if (ti = FindTagItem(MPG_CHELP,gh->TagList)) {
  1058.         gh->CHelp = ti->ti_Data;
  1059.     }
  1060.     if (ti = FindTagItem(MPG_PARAMS,gh->TagList)) {
  1061.         gh->Params = (char **)ti->ti_Data;
  1062.     }
  1063.     if (ti = FindTagItem(MPG_NEWLINE,gh->TagList)) {
  1064.         gh->NewLine = ti->ti_Data;
  1065.     }
  1066.     if (ti = FindTagItem(MPG_PREFS,gh->TagList)) {
  1067.         gh->Prefs = ti->ti_Data;
  1068.     }
  1069.     if (ti = FindTagItem(MPG_NOBUTTONS,gh->TagList)) {
  1070.         gh->NoButtons = ti->ti_Data;
  1071.         if (gh->NoButtons) {
  1072.             gh->Prefs = FALSE;
  1073.         }
  1074.     }
  1075.     if (ti = FindTagItem(MPG_BUTTONHOOK,gh->TagList)) {
  1076.         gh->ButtonFunc = (struct Hook *)ti->ti_Data;
  1077.     }
  1078.     if (ti = FindTagItem(MPG_MENUS,gh->TagList)) {
  1079.         gh->NewMenu = (struct NewMenu *)ti->ti_Data;
  1080.     }
  1081.     if (ti = FindTagItem(MPG_MENUHOOK,gh->TagList)) {
  1082.         gh->MenuFunc = (struct Hook *)ti->ti_Data;
  1083.     }
  1084.     else {
  1085.         gh->Menu = FALSE;
  1086.     }
  1087.     if (ti = FindTagItem(MPG_SIGNALHOOK,gh->TagList)) {
  1088.         if (ti->ti_Data) {
  1089.             gh->SignalFunc = (struct Hook *)ti->ti_Data;
  1090.             if (ti = FindTagItem(MPG_SIGNALS,gh->TagList)) {
  1091.                 gh->Signals = ti->ti_Data;
  1092.             }
  1093.         }
  1094.     }
  1095.     gh->MyTextAttr = gh->MyScreen->Font;
  1096.     if (gh->MyScreen) {
  1097.         if (gh->fp = Open(fname,MODE_OLDFILE)) {
  1098.             if (myfgets(gh)) {
  1099.                 if (gh->buffer[0] == '"') {
  1100.                     Command(gh);
  1101.                 }
  1102.                 else {
  1103.                     pError(gh,GetMessage(MSG_ERR_NOSQ),gh->buffer);
  1104.                 }
  1105.             }
  1106.             else {
  1107.                 pError(gh,GetMessage(MSG_ERR_NOCOM),NULL);
  1108.             }
  1109.         }
  1110.         else {
  1111.             pError(gh,GetMessage(MSG_ERR_OPENF),fname);
  1112.         }
  1113.     }
  1114.     else {
  1115.         pError(gh,GetMessage(MSG_ERR_LOCKS),NULL);
  1116.     }
  1117.     if (!gh->FoundError) {
  1118.         ULONG temp,temp1;
  1119.         if (gh->allsize > (gh->leftsize + gh->rightsize)) {
  1120.             gh->rightsize = gh->allsize - gh->leftsize;
  1121.         }
  1122.         if (gh->tallsize > (gh->tleftsize + gh->trightsize)) {
  1123.             gh->trightsize = gh->tallsize - gh->tleftsize;
  1124.         }
  1125.         temp = gh->MyScreen->WBorTop + gh->MyScreen->Font->ta_YSize + 1 + gh->MyScreen->WBorBottom -
  1126.              (INTERHEIGHT + 1) * gh->extralist;
  1127.         temp1 = gh->numlines+(gh->NoButtons?0:1)+(gh->HelpMessageB?1:0)+1;
  1128.         if (temp + (gh->MyScreen->Font->ta_YSize + 2 + INTERHEIGHT)*temp1 >
  1129.                                         gh->MyScreen->Height) {
  1130.             if (temp + (gh->MyScreen->Font->ta_YSize + 2 + (INTERHEIGHT/2))*temp1 >
  1131.                                             gh->MyScreen->Height) {
  1132.                 if (temp + (GfxBase->DefaultFont->tf_YSize + 2 + INTERHEIGHT)*temp1 >
  1133.                                                 gh->MyScreen->Height) {
  1134.                     if (temp + (GfxBase->DefaultFont->tf_YSize + 2 + INTERHEIGHT/2)*temp1 >
  1135.                                                     gh->MyScreen->Height) {
  1136.                         if (temp + (8 + 2 + INTERHEIGHT)*temp1 >
  1137.                                                         gh->MyScreen->Height) {
  1138.                             gh->interwidth = INTERWIDTH;
  1139.                             gh->interheight = (INTERHEIGHT/2);
  1140.                             gh->Attr.ta_Name = (STRPTR)"topaz.font";
  1141.                             gh->Attr.ta_YSize = 8;
  1142.                             gh->MyTextAttr = &(gh->Attr);
  1143.                             gh->leftsize = gh->tleftsize;
  1144.                             gh->rightsize = gh->trightsize;
  1145.                             gh->UseTopaz = TRUE;
  1146.                             gh->XSize = 8;
  1147.                             if (temp + (8 + 2 + INTERHEIGHT/2)*temp1 >
  1148.                                                                 gh->MyScreen->Height) {
  1149.                                 if ((gh->leftsize*2 + gh->rightsize*2 + (gh->interwidth * 2) +
  1150.                                       gh->MyScreen->WBorLeft + gh->MyScreen->WBorRight) > gh->MyScreen->Width) {
  1151.                                     gh->rightsize = (gh->MyScreen->Width - 2 * gh->leftsize - (gh->interwidth * 2) -
  1152.                                                           gh->MyScreen->WBorLeft - gh->MyScreen->WBorRight) / 2;
  1153.                                 }
  1154.                             }
  1155.                         }
  1156.                         else {
  1157.                             gh->interwidth = INTERWIDTH;
  1158.                             gh->interheight = INTERHEIGHT;
  1159.                             gh->Attr.ta_Name = (STRPTR)"topaz.font";
  1160.                             gh->Attr.ta_YSize = 8;
  1161.                             gh->MyTextAttr = &(gh->Attr);
  1162.                             gh->leftsize = gh->tleftsize;
  1163.                             gh->rightsize = gh->trightsize;
  1164.                             gh->UseTopaz = TRUE;
  1165.                             gh->XSize = 8;
  1166.                         }
  1167.                     }
  1168.                     else {
  1169.                         gh->interwidth = INTERWIDTH;
  1170.                         gh->interheight = (INTERHEIGHT/2);
  1171.                         gh->Attr.ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  1172.                         gh->Attr.ta_YSize = GfxBase->DefaultFont->tf_YSize;
  1173.                         gh->MyTextAttr = &(gh->Attr);
  1174.                         gh->leftsize = (gh->tleftsize * GfxBase->DefaultFont->tf_XSize)/8;
  1175.                         gh->rightsize = (gh->trightsize * GfxBase->DefaultFont->tf_XSize)/8;
  1176.                         gh->UseTopaz = TRUE;
  1177.                         gh->XSize = GfxBase->DefaultFont->tf_XSize;
  1178.                     }
  1179.                 }
  1180.                 else {
  1181.                     gh->interwidth = INTERWIDTH;
  1182.                     gh->interheight = INTERHEIGHT;
  1183.                     gh->Attr.ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  1184.                     gh->Attr.ta_YSize = GfxBase->DefaultFont->tf_YSize;
  1185.                     gh->MyTextAttr = &(gh->Attr);
  1186.                     gh->leftsize = (gh->tleftsize * GfxBase->DefaultFont->tf_XSize)/8;
  1187.                     gh->rightsize = (gh->trightsize * GfxBase->DefaultFont->tf_XSize)/8;
  1188.                     gh->UseTopaz = TRUE;
  1189.                     gh->XSize = GfxBase->DefaultFont->tf_XSize;
  1190.                 }
  1191.             }
  1192.             else {
  1193.                 gh->interwidth = INTERWIDTH;
  1194.                 gh->interheight = INTERHEIGHT/2;
  1195.             }
  1196.         }
  1197.         else {
  1198.             gh->interwidth = INTERWIDTH;
  1199.             gh->interheight = INTERHEIGHT;
  1200.         }
  1201.         RequesterStuff(gh);
  1202.     }
  1203.     if (gh->MyScreen) {
  1204.         UnlockPubScreen(NULL,gh->MyScreen);
  1205.     }
  1206.     if (gh->fp) {
  1207.         Close(gh->fp);
  1208.     }
  1209.     if (gh->FoundError) {
  1210.         return (char *)-1;
  1211.     }
  1212.     else {
  1213.         if (gh->result[0]) {
  1214.             return gh->result;
  1215.         }
  1216.         else {
  1217.             return NULL;
  1218.         }
  1219.     }
  1220. }
  1221.  
  1222. /****** MPGui.library/ReadMPGui *********************************************
  1223. *
  1224. *   NAME   
  1225. *  ReadMPGui -- Reads information for an MPGui. (V4)
  1226. *
  1227. *   SYNOPSIS
  1228. *  result = ReadMPGui( fname, gh)
  1229. *  D0                         A0     A1
  1230. *
  1231. *  BOOL ReadMPGui( char *, struct MPGuiHandle *);
  1232. *
  1233. *   FUNCTION
  1234. *  Reads all the information in the file for an MPGuiHandle allocated by
  1235. *  AllocMPGuiHandle().
  1236. *
  1237. *   INPUTS
  1238. *  fname - name of file describing gui.
  1239. *  gh    - MPGuiHandle allocated by AllocMPGuiHandle().
  1240. *
  1241. *   RESULT
  1242. *  TRUE if file read OK
  1243. *  FALSE for error. Use MPGuiError() to get error.
  1244. *
  1245. *   EXAMPLE
  1246. *
  1247. *   NOTES
  1248. *  Ignores any tags supplied to AllocMPGuiHandleA().
  1249. *
  1250. *  This currently serves no purpose, but may be later used for a gui based
  1251. *  gui designer.
  1252. *
  1253. *   BUGS
  1254. *
  1255. * Currently does nothing!
  1256. * Does not handle TEXT/MTEXT
  1257. *
  1258. *   SEE ALSO
  1259. *  AllocMPGuiHandleA(),MPGuiError(),WriteMPGui().
  1260. *
  1261. *****************************************************************************
  1262. *
  1263. */
  1264. BOOL __saveds __asm
  1265. ReadMPGui(register __a0 char *fname,register __a1 struct MPGuiHandle *gh) {
  1266. #if 0
  1267.     if (!fname || !gh) {
  1268.         pError(gh,GetMessage(MSG_ERR_NOPR),NULL);
  1269.         return FALSE;
  1270.     }
  1271.     if (gh->fp = Open(fname,MODE_OLDFILE)) {
  1272.         if (myfgets(gh)) {
  1273.             if (gh->buffer[0] == '"') {
  1274.                 Command(gh);
  1275.             }
  1276.             else {
  1277.                 pError(gh,GetMessage(MSG_ERR_NOSQ),gh->buffer);
  1278.             }
  1279.         }
  1280.         else {
  1281.             pError(gh,GetMessage(MSG_ERR_NOCOM),NULL);
  1282.         }
  1283.         Close(gh->fp);
  1284.     }
  1285.     else {
  1286.         pError(gh,GetMessage(MSG_ERR_OPENF),fname);
  1287.     }
  1288.     if (gh->FoundError) {
  1289.         return FALSE;
  1290.     }
  1291.     else {
  1292.         return TRUE;
  1293.     }
  1294. #else
  1295.     return TRUE;
  1296. #endif
  1297. }
  1298.  
  1299. #if 0
  1300. void
  1301. PrintHelp(struct MPGuiHandle *gh,struct MyGadget *gad) {
  1302.     if (gad->HelpNode) {
  1303.         if (gad->HelpMessage) {
  1304.             FPrintf(gh->fp,"!%s!%s!",gad->HelpNode,gad->HelpMessage);
  1305.         }
  1306.         else {
  1307.             FPrintf(gh->fp,"!%s!!",gad->HelpNode);
  1308.         }
  1309.     }
  1310.     else {
  1311.         if (gad->HelpMessage) {
  1312.             FPrintf(gh->fp,"!!%s!",gad->HelpMessage);
  1313.         }
  1314.         else {
  1315.             FPrintf(gh->fp,"!!!");
  1316.         }
  1317.     }
  1318. }
  1319.  
  1320. BOOL
  1321. PrintGadget(struct MPGuiHandle *gh,struct MyGadget *gad) {
  1322.     struct MyGadget *gad1;
  1323.     struct MyValue *val;
  1324.     int i,j;
  1325.     char *type;
  1326.     if (gad->OwnCycle) {
  1327.         FPuts(gh->fp,"\t\t");
  1328.     }
  1329.     else {
  1330.         FPutC(gh->fp,'\t');
  1331.     }
  1332.     switch (gad->Type) {
  1333.     case GAD_LFILE:
  1334.         type = "LFILE";
  1335.         break;
  1336.     case GAD_SFILE:
  1337.         type = "SFILE";
  1338.         break;
  1339.     case GAD_FILE:
  1340.         type = "FILE";
  1341.         break;
  1342.     case GAD_OFILE:
  1343.         type = "OFILE";
  1344.         break;
  1345.     case GAD_ONUMBER:
  1346.         type = "ONUMBER";
  1347.         break;
  1348.     case GAD_NUMBER:
  1349.         type = "NUMBER";
  1350.         break;
  1351.     case GAD_CYCLE:
  1352.         type = "CYCLE";
  1353.         break;
  1354.     case GAD_STRING:
  1355.         type = "STRING";
  1356.         break;
  1357.     case GAD_OSTRING:
  1358.         type = "OSTRING";
  1359.         break;
  1360.     case GAD_CHECK:
  1361.         type = "CHECK";
  1362.         break;
  1363.     case GAD_SLIDER:
  1364.         type = "SLIDER";
  1365.         break;
  1366.     case GAD_MODE:
  1367.         type = "MODE";
  1368.         break;
  1369.     case GAD_OMODE:
  1370.         type = "OMODE";
  1371.         break;
  1372.     case GAD_FONT:
  1373.         type = "FONT";
  1374.         break;
  1375.     case GAD_OFONT:
  1376.         type = "OFONT";
  1377.         break;
  1378.     case GAD_LIST:
  1379.         type = "LIST";
  1380.         break;
  1381.     case GAD_MLIST:
  1382.         type = "MLIST";
  1383.         break;
  1384.     case GAD_BUTTONTEXT:
  1385.         type = "BUTTON";
  1386.         break;
  1387.     case GAD_BUTTON:
  1388.         break;
  1389.     default:
  1390.         break;
  1391.     }
  1392.     switch (gad->Type) {
  1393.     case GAD_LFILE:
  1394.     case GAD_SFILE:
  1395.     case GAD_FILE:
  1396.     case GAD_STRING:
  1397.         FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%s\"",type,gad->Title,gad->Prefix,gad->Defaults);
  1398.         PrintHelp(gh,gad);
  1399.         FPutC(gh->fp,'\n');
  1400.         break;
  1401.     case GAD_OFILE:
  1402.     case GAD_OSTRING:
  1403.         FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%s\":%s",type,gad->Title,gad->Prefix,gad->Defaults,
  1404.                                                                     gad->Defaultc?"Y":"N");
  1405.         PrintHelp(gh,gad);
  1406.         FPutC(gh->fp,'\n');
  1407.         break;
  1408.     case GAD_ONUMBER:
  1409.         FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%ld\":%s",type,gad->Title,gad->Prefix,gad->Defaultn,
  1410.                                                                     gad->Defaultc?"Y":"N");
  1411.         PrintHelp(gh,gad);
  1412.         FPutC(gh->fp,'\n');
  1413.         break;
  1414.     case GAD_NUMBER:
  1415.         FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%ld\"",type,gad->Title,gad->Prefix,gad->Defaultn);
  1416.         PrintHelp(gh,gad);
  1417.         FPutC(gh->fp,'\n');
  1418.         break;
  1419.     case GAD_CYCLE:
  1420.         FPrintf(gh->fp,"%s \"%s\"",type,gad->Title);
  1421.         PrintHelp(gh,gad);
  1422.         FPutC(gh->fp,'\n');
  1423.         i = 0;
  1424.         for (gad1 = (struct MyGadget *)(gh->GList.lh_Head);
  1425.               gad1->GNode.ln_Succ;
  1426.               gad1 = (struct MyGadget *)(gad1->GNode.ln_Succ)){
  1427.             if (gad == gad1->OwnCycle) {
  1428.                 for (; !(i > gad1->Activey); i++) {
  1429.                     val = (struct MyValue *)gad->VList.lh_Head;
  1430.                     for (j = 0; (j < i); j++) {
  1431.                         val = (struct MyValue *)val->VNode.ln_Succ;
  1432.                     }
  1433.                     FPrintf(gh->fp,"\t\"%s\":\"%s\"\n",val->VNode.ln_Name,val->Prefix);
  1434.                 }
  1435.                 PrintGadget(gh,gad1);
  1436.             }
  1437.         }
  1438.         for (; (i < gad->Numbery); i++) {
  1439.             val = (struct MyValue *)gad->VList.lh_Head;
  1440.             for (j = 0; (j < i); j++) {
  1441.                 val = (struct MyValue *)val->VNode.ln_Succ;
  1442.             }
  1443.             FPrintf(gh->fp,"\t\"%s\":\"%s\"\n",val->VNode.ln_Name,val->Prefix);
  1444.         }
  1445.         FPrintf(gh->fp,"\t%s:\"%ld\"\n","ENDCYCLE",gad->Defaulty);
  1446.         break;
  1447.     case GAD_CHECK:
  1448.         if (gad->NPrefix) {
  1449.             FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%s\":%s",type,gad->Title,gad->Prefix,
  1450.                                                                     gad->NPrefix,gad->Defaultc?"Y":"N");
  1451.         }
  1452.         else {
  1453.             FPrintf(gh->fp,"%s \"%s\":\"%s\":%s",type,gad->Title,gad->Prefix,
  1454.                                                                     gad->Defaultc?"Y":"N");
  1455.         }
  1456.         PrintHelp(gh,gad);
  1457.         FPutC(gh->fp,'\n');
  1458.         break;
  1459.     case GAD_SLIDER:
  1460.         FPrintf(gh->fp,"%s \"%s\":\"%s\":\"%ld\":\"%ld\":\"%ld\"",type,gad->Title,gad->Prefix,
  1461.                                                                             gad->Minn,gad->Maxn,gad->Defaultn);
  1462.         PrintHelp(gh,gad);
  1463.         FPutC(gh->fp,'\n');
  1464.         break;
  1465.     case GAD_MODE:
  1466.     case GAD_FONT:
  1467.         FPrintf(gh->fp,"%s%ld \"%s\":\"%s\":\"%s\"",type,gad->ModeType,gad->Title,gad->Prefix,
  1468.                                                                             gad->Defaults);
  1469.         PrintHelp(gh,gad);
  1470.         FPutC(gh->fp,'\n');
  1471.         break;
  1472.     case GAD_OMODE:
  1473.     case GAD_OFONT:
  1474.         FPrintf(gh->fp,"%s%ld \"%s\":\"%s\":\"%s\":%s",type,gad->ModeType,gad->Title,gad->Prefix,
  1475.                                                                             gad->Defaults,gad->Defaultc?"Y":"N");
  1476.         PrintHelp(gh,gad);
  1477.         FPutC(gh->fp,'\n');
  1478.         break;
  1479.     case GAD_LIST:
  1480.         FPrintf(gh->fp,"%s \"%s\"",type,gad->Title);
  1481.         PrintHelp(gh,gad);
  1482.         FPutC(gh->fp,'\n');
  1483.         val = (struct MyValue *)gad->VList.lh_Head;
  1484.         for (i=0; (i < gad->Numbery); i++) {
  1485.             if (gad->OwnCycle) {
  1486.                 FPutC(gh->fp,'\t');
  1487.             }
  1488.             FPrintf(gh->fp,"\t\t\"%s\":\"%s\"\n",val->VNode.ln_Name,val->Prefix);
  1489.             val = (struct MyValue *)val->VNode.ln_Succ;
  1490.         }
  1491.         if (gad->OwnCycle) {
  1492.             FPutC(gh->fp,'\t');
  1493.         }
  1494.         FPrintf(gh->fp,"\t%s:\"%ld\":\"%ld\"\n","ENDLIST",gad->Defaulty,gad->Lines);
  1495.         break;
  1496.     case GAD_MLIST:
  1497.         FPrintf(gh->fp,"%s \"%s\"",type,gad->Title);
  1498.         PrintHelp(gh,gad);
  1499.         FPutC(gh->fp,'\n');
  1500.         val = (struct MyValue *)gad->VList.lh_Head;
  1501.         for (i=0; (i < gad->Numbery); i++) {
  1502.             if (gad->OwnCycle) {
  1503.                 FPutC(gh->fp,'\t');
  1504.             }
  1505.             if (val->NPrefix) {
  1506.                 FPrintf(gh->fp,"\t\t\"%s\":\"%s\":\"%s\"\n",val->VNode.ln_Name,val->Prefix,val->NPrefix);
  1507.             }
  1508.             else {
  1509.                 FPrintf(gh->fp,"\t\t\"%s\":\"%s\"\n",val->VNode.ln_Name,val->Prefix);
  1510.             }
  1511.             val = (struct MyValue *)val->VNode.ln_Succ;
  1512.         }
  1513.         if (gad->OwnCycle) {
  1514.             FPutC(gh->fp,'\t');
  1515.         }
  1516.         FPrintf(gh->fp,"\t%s:\"%s\":\"%ld\"\n","ENDMLIST",gad->Defaults,gad->Lines);
  1517.         break;
  1518.     case GAD_BUTTONTEXT:
  1519.         {
  1520.             struct MyGadget* gad1;
  1521.             FPrintf(gh->fp,"\t%s:\"%s\"\n",type,gad->Title);
  1522.             for (gad1 = (struct MyGadget *)gad->GNode.ln_Succ;
  1523.                   gad1->GNode.ln_Succ && (GAD_BUTTON == gad1->Type);
  1524.                   gad1 = (struct MyGadget *)gad1->GNode.ln_Succ) {
  1525.                 if (gad->OwnCycle) {
  1526.                     FPutC(gh->fp,'\t');
  1527.                 }
  1528.                 FPrintf(gh->fp,"\t\t\"%s\":\"%ld\"",gad1->Title,gad1->ButtonNo);
  1529.                 PrintHelp(gh,gad1);
  1530.                 FPutC(gh->fp,'\n');
  1531.             }
  1532.             if (gad->OwnCycle) {
  1533.                 FPutC(gh->fp,'\t');
  1534.             }
  1535.             FPrintf(gh->fp,"\tENDBUTTON\n");
  1536.         }
  1537.         break;
  1538.     case GAD_BUTTON:
  1539.         break;
  1540.     default:
  1541.         FPuts(gh->fp,"??\n");
  1542.         break;
  1543.     }
  1544.     return TRUE;
  1545. }
  1546.  
  1547. /****** MPGui.library/WriteMPGui ********************************************
  1548. *
  1549. *   NAME   
  1550. *  WriteMPGui -- Writes information for an MPGui. (V4)
  1551. *
  1552. *   SYNOPSIS
  1553. *  result = WriteMPGui( fname, gh)
  1554. *  D0                         A0     A1
  1555. *
  1556. *  BOOL WriteMPGui( char *, struct MPGuiHandle *);
  1557. *
  1558. *   FUNCTION
  1559. *  Writes all the information in the file for an MPGuiHandle allocated by
  1560. *  AllocMPGuiHandle().
  1561. *
  1562. *   INPUTS
  1563. *  fname - name of file to describe the gui.
  1564. *  gh    - MPGuiHandle allocated by AllocMPGuiHandle().
  1565. *
  1566. *   RESULT
  1567. *  TRUE if file written OK
  1568. *  FALSE for error. Use MPGuiError() to get error.
  1569. *
  1570. *   EXAMPLE
  1571. *
  1572. *   NOTES
  1573. *  Ignores any tags supplied to AllocMPGuiHandleA().
  1574. *
  1575. *  This currently serves no purpose, but may be later used for a gui based
  1576. *  gui designer.
  1577. *
  1578. *   BUGS
  1579. *
  1580. * Currently does nothing!
  1581. * Does not handle TEXT/MTEXT
  1582. *
  1583. *   SEE ALSO
  1584. *  AllocMPGuiHandleA(),MPGuiError(),ReadMPGui().
  1585. *
  1586. *****************************************************************************
  1587. *
  1588. */
  1589. #endif
  1590. BOOL __saveds __asm
  1591. WriteMPGui(register __a0 char *fname,register __a1 struct MPGuiHandle *gh) {
  1592. #if 0
  1593.     int i;
  1594.     struct MyGadget *gad;
  1595.     if (!fname || !gh) {
  1596.         pError(gh,GetMessage(MSG_ERR_NOPW),NULL);
  1597.         return FALSE;
  1598.     }
  1599.     if (gh->fp = Open(fname,MODE_NEWFILE)) {
  1600.         for (i=0; i<6; i++) {
  1601.             if (gh->comment[i]) {
  1602.                 FPrintf(gh->fp,"%s\n",gh->comment[i]);
  1603.             }
  1604.         }
  1605.         FPutC(gh->fp,'\n');
  1606.         FPrintf(gh->fp,"\"%s\"%s",gh->Command,gh->HelpMessage);
  1607.         FPrintf(gh->fp,"\t\"%s\"\n",gh->Comment);
  1608.         FPrintf(gh->fp,"\t\"%s\"\n",gh->HelpNode);
  1609.         for (gad = (struct MyGadget *)gh->GList.lh_Head;
  1610.               gad->GNode.ln_Succ;
  1611.               gad = (struct MyGadget *)gad->GNode.ln_Succ) {
  1612.             if (!gad->OwnCycle) {
  1613.                 PrintGadget(gh,gad);
  1614.             }
  1615.         }
  1616.         Close(gh->fp);
  1617.     }
  1618.     else {
  1619.         pError(gh,GetMessage(MSG_ERR_OPENF),fname);
  1620.     }
  1621.     if (gh->FoundError) {
  1622.         return FALSE;
  1623.     }
  1624.     else {
  1625.         return TRUE;
  1626.     }
  1627. #else
  1628.     return TRUE;
  1629. #endif
  1630. }
  1631.  
  1632. /****** MPGui.library/RefreshMPGui ******************************************
  1633. *
  1634. *   NAME   
  1635. *  RefreshMPGui -- Refreshes an MPGui Window. (V5)
  1636. *
  1637. *   SYNOPSIS
  1638. *  RefreshMPGui(gh)
  1639. *               A0
  1640. *
  1641. *  void RefreshMPGui(struct MPGuiHandle *);
  1642. *
  1643. *   FUNCTION
  1644. *  Refreshes an MPGui Window.
  1645. *
  1646. *   INPUTS
  1647. *  gh    - MPGuiHandle allocated by AllocMPGuiHandle().
  1648. *
  1649. *   RESULT
  1650. *  None
  1651. *
  1652. *   EXAMPLE
  1653. *
  1654. *   NOTES
  1655. *  Use in a call back hook - e.g. if a menu item opens a file requester.
  1656. *
  1657. *   BUGS
  1658. *
  1659. *   SEE ALSO
  1660. *  AllocMPGuiHandleA(), SyncMPGuiRequest().
  1661. *
  1662. *****************************************************************************
  1663. *
  1664. */
  1665. void __saveds __asm
  1666. RefreshMPGui(register __a0 struct MPGuiHandle *gh) {
  1667.     if (gh) {
  1668.         if (gh->Window) {
  1669.             GT_BeginRefresh(gh->Window);
  1670.             GT_EndRefresh(gh->Window,TRUE);
  1671.         }
  1672.     }
  1673. }
  1674.  
  1675. /****** MPGui.library/MPGuiWindow *******************************************
  1676. *
  1677. *   NAME   
  1678. *  MPGuiWindow -- Returns the Window for an MPGui. (V5)
  1679. *
  1680. *   SYNOPSIS
  1681. *  Window = MPGuiWindow(gh)
  1682. *  D0                   A0
  1683. *
  1684. *  struct Window *MPGuiWindow(struct MPGuiHandle *);
  1685. *
  1686. *   FUNCTION
  1687. *  Returns the Window for an MPGui.
  1688. *
  1689. *   INPUTS
  1690. *  gh    - MPGuiHandle allocated by AllocMPGuiHandle().
  1691. *
  1692. *   RESULT
  1693. *  The Window for the GUI - if open.
  1694. *
  1695. *   EXAMPLE
  1696. *
  1697. *   NOTES
  1698. *  Use in a call back hook - e.g. if a menu item opens a file requester.
  1699. *
  1700. *   BUGS
  1701. *
  1702. *   SEE ALSO
  1703. *  AllocMPGuiHandleA(), SyncMPGuiRequest().
  1704. *
  1705. *****************************************************************************
  1706. *
  1707. */
  1708. struct Window * __saveds __asm
  1709. MPGuiWindow(register __a0 struct MPGuiHandle *gh) {
  1710.     if (gh) {
  1711.         return gh->Window;
  1712.     }
  1713.     return NULL;
  1714. }
  1715.  
  1716. int
  1717. sprintf(char *buffer,const char *ctl, ...) {
  1718.    va_list args;
  1719.  
  1720.    va_start(args, ctl);
  1721.  
  1722.    /*********************************************************/
  1723.    /* NOTE: The string below is actually CODE that copies a */
  1724.    /*       value from d0 to A3 and increments A3:          */
  1725.    /*                                                       */
  1726.    /*          move.b d0,(a3)+                              */
  1727.    /*          rts                                          */
  1728.    /*                                                       */
  1729.    /*       It is essentially the callback routine needed   */
  1730.    /*       by RawDoFmt.                                    */
  1731.    /*********************************************************/
  1732.  
  1733.    RawDoFmt((char *)ctl, args, (void (*))"\x16\xc0\x4e\x75", buffer);
  1734.  
  1735.    va_end(args);
  1736.  
  1737.    return 0;
  1738. }
  1739.  
  1740. /* clone of strdup using pooled memory */
  1741. char
  1742. *mystrdup(struct MPGuiHandle *gh,char *old) {
  1743.     char *ptr;
  1744.     if (!old) {
  1745.         return NULL;
  1746.     }
  1747.     if (ptr = AllocPooled(gh->MemPool,strlen(old)+1)) {
  1748.         strcpy(ptr,old);
  1749.     }
  1750.     return ptr;
  1751. }
  1752.  
  1753. /* Does all the input file processing for a command */
  1754. void
  1755. Command(struct MPGuiHandle *gh) {
  1756.     char *s,*s1;
  1757.     NewList(&(gh->GList));
  1758.     s = strchr(&(gh->buffer[1]),'"');
  1759.     if (s) {
  1760.         *s = 0;
  1761.         gh->Command = mystrdup(gh,&(gh->buffer[1]));
  1762.         gh->HelpMessage = mystrdup(gh,++s);
  1763.         while ((s = myfgets(gh)) && !strchr(gh->buffer,'"')) {
  1764.         }
  1765.         if (s) {
  1766.             s = strchr(gh->buffer,'"');
  1767.             s1 = strchr(s+1,'"');
  1768.             if (s1) {
  1769.                 *s1=0;
  1770.                 gh->Comment = mystrdup(gh,s+1);
  1771.                 if (!gh->HelpMessage) {
  1772.                     gh->HelpMessage = gh->Comment;
  1773.                 }
  1774.                 gh->TitleLength = TextLength(&(gh->MyScreen->RastPort),gh->Comment,strlen(gh->Comment));
  1775.                 if (myfgets(gh)) {
  1776.                     s = strchr(gh->buffer,'"');
  1777.                     if (s) {
  1778.                         s1 = strchr(s+1,'"');
  1779.                         if (s1) {
  1780.                             *s1=0;
  1781.                             gh->HelpNode = mystrdup(gh,s+1);
  1782.                             while (myfgets(gh)) {
  1783.                                 ProcessGadget(gh);
  1784.                             }
  1785.                          }
  1786.                         else {
  1787.                             pError(gh,GetMessage(MSG_ERR_TEEQ),NULL);
  1788.                             while (myfgets(gh) && (gh->buffer[0] != '\n')) {
  1789.                             }
  1790.                         }
  1791.                     }
  1792.                     else {
  1793.                         pError(gh,GetMessage(MSG_ERR_TSSQ),NULL);
  1794.                         while (myfgets(gh) && (gh->buffer[0] != '\n')) {
  1795.                         }
  1796.                     }
  1797.                 }
  1798.                 else {
  1799.                     pError(gh,GetMessage(MSG_ERR_TEOF),NULL);
  1800.                 }
  1801.             }
  1802.             else {
  1803.                 pError(gh,GetMessage(MSG_ERR_COMMTQ),NULL);
  1804.             }
  1805.         }
  1806.         else {
  1807.             pError(gh,GetMessage(MSG_ERR_COMEOF),NULL);
  1808.         }
  1809.     }
  1810.     else {
  1811.         pError(gh,GetMessage(MSG_ERR_COMTQ),NULL);
  1812.     }
  1813. }
  1814.  
  1815. void
  1816. pError(struct MPGuiHandle *gh,const char *a,char *b) {
  1817.     if (!gh->OutOfMemory) {
  1818.         sprintf(gh->TempFileName,GetMessage(MSG_ERR_LINE),gh->linenumber);
  1819.         strncat(gh->error,gh->TempFileName,1024);
  1820.         sprintf(gh->TempFileName,a,b);
  1821.         strncat(gh->error,gh->TempFileName,1024);
  1822.         strncat(gh->error,"\n",1024);
  1823.     }
  1824.     ++gh->FoundError;
  1825. }
  1826.  
  1827. static char wbuffer[2048];
  1828.  
  1829. char
  1830. *myfgets(struct MPGuiHandle *gh) {
  1831.     char *s;
  1832.     int i;
  1833.     if ((gh->FoundError > 10) || (gh->OutOfMemory)) {
  1834.         return NULL;
  1835.     }
  1836.     ++gh->linenumber;
  1837.     while ((s = FGets(gh->fp,gh->buffer,256)) && ((gh->buffer[0] == '*') || (gh->buffer[0] == '\n'))) {
  1838.         if (gh->buffer[0] == '*') {
  1839.             if (!gh->comment[6]) {
  1840.                 for (i=0; i<6; i++) {
  1841.                     if (!gh->comment[i]) {
  1842.                         s[strlen(s)-1] = 0;
  1843.                         gh->comment[i] = mystrdup(gh,s);
  1844.                         i=6;
  1845.                     }
  1846.                 }
  1847.             }
  1848.         }
  1849.         ++gh->linenumber;
  1850.     }
  1851.     if (!s) {
  1852.         return NULL;
  1853.     }
  1854.     s[strlen(s)-1] = 0;
  1855.     // Convert \ formats, \" is converted to 1 and converted back later
  1856.     if (strstr(s,"\\")) {
  1857.         char *s1,*s2;
  1858.         s1 = s;
  1859.         s2 = wbuffer;
  1860.         while (*s1) {
  1861.             if ('\\' == *s1) {
  1862.                 ++s1;
  1863.                 switch (*s1) {
  1864.                 case '\\':
  1865.                     *s2++ = '\\';
  1866.                     ++s1;
  1867.                     break;
  1868.                 case '"':
  1869.                     *s2++ = '\001';
  1870.                     ++s1;
  1871.                     break;
  1872.                 case 't':
  1873.                     *s2++ = '\t';
  1874.                     ++s1;
  1875.                     break;
  1876.                 case 'n':
  1877.                     *s2++ = '\n';
  1878.                     ++s1;
  1879.                     break;
  1880.                 default:
  1881.                     *s2++ = *s1++;
  1882.                     break;
  1883.                 }
  1884.             }
  1885.             else {
  1886.                 *s2++ = *s1++;
  1887.             }
  1888.         }
  1889.         *s2 = 0;
  1890.         strcpy(gh->buffer,wbuffer);
  1891.         s = gh->buffer;
  1892.     }
  1893.     if (!gh->Params || !s) {
  1894.         return s;
  1895.     }
  1896.     else {
  1897.         char *s1,*s2,*s3;
  1898.         BOOL found = FALSE;
  1899.         BOOL flag;
  1900.         int i,j;
  1901.  
  1902.         s1 = s;
  1903.         s2 = wbuffer;
  1904.         while (*s1) {
  1905.             if (*s1 != '#') {
  1906.                 *s2++ = *s1++;
  1907.             }
  1908.             else {
  1909.                 found = TRUE;
  1910.                 s1++;
  1911.                 if (*s1 == '#') {
  1912.                     *s2++ = *s1++;
  1913.                 }
  1914.                 else {
  1915.                     if (isdigit(*s1)) {
  1916.                         i = atoi(s1);
  1917.                         flag = TRUE;
  1918.                         for (j = 0; j<(i+1); ++j) {
  1919.                             if (!gh->Params[j]) {
  1920.                                 flag = FALSE;
  1921.                                 j = i+1;
  1922.                             }
  1923.                         }
  1924.                         if (flag) {
  1925.                             s3 = gh->Params[i];
  1926.                         }
  1927.                         else {
  1928.                             s3 = "";
  1929.                         }
  1930.                         while (*s3) {
  1931.                             *s2++ = *s3++;
  1932.                         }
  1933.                         while (*s1 && (*s1 != '#')) {
  1934.                             s1++;
  1935.                         }
  1936.                         if (*s1) {
  1937.                             s1++;
  1938.                         }
  1939.                     }
  1940.                 }
  1941.             }
  1942.         }
  1943.         if (!found) {
  1944.             return s;
  1945.         }
  1946.         else {
  1947.             *s2 = 0;
  1948.             strcpy(gh->buffer,wbuffer);
  1949.             return gh->buffer;
  1950.         }
  1951.     }
  1952. }
  1953.  
  1954. #define ALPHA (char *)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  1955. #define NUMBER (char *)"0123456789"
  1956.  
  1957. void
  1958. ProcessGadget(struct MPGuiHandle *gh) {
  1959.     char *s;
  1960.     int temp=0,temp1=0;
  1961.  
  1962.     if (gh->CurrentGadget = (struct MyGadget *)AllocPooled(gh->MemPool,sizeof(struct MyGadget))) {
  1963.         NewList(&(gh->CurrentGadget->VList));
  1964.         AddTail(&(gh->GList),&(gh->CurrentGadget->GNode));
  1965.         if (gh->CurrentCycle) {
  1966.             gh->CurrentGadget->Activey = gh->CurrentCycleVal;
  1967.             gh->CurrentGadget->OwnCycle = gh->CurrentCycle;
  1968.         }
  1969.     }
  1970.     else {
  1971.         pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  1972.         gh->OutOfMemory = 1;
  1973.         return;
  1974.     }
  1975.     s = SkipSpace(gh->buffer);
  1976.     if (s) {
  1977.         if (!strncmp(s,"FILE",strlen("FILE"))) {
  1978.             gh->CurrentGadget->Type = GAD_FILE;
  1979.         }
  1980.         else if (!strncmp(s,"LFILE",strlen("LFILE"))) {
  1981.             gh->CurrentGadget->Type = GAD_LFILE;
  1982.         }
  1983.         else if (!strncmp(s,"SFILE",strlen("SFILE"))) {
  1984.             gh->CurrentGadget->Type = GAD_SFILE;
  1985.         }
  1986.         else if (!strncmp(s,"OFILE",strlen("OFILE"))) {
  1987.             gh->CurrentGadget->Type = GAD_OFILE;
  1988.         }
  1989.         else if (!strncmp(s,"ONUMBER",strlen("ONUMBER"))) {
  1990.             gh->CurrentGadget->Type = GAD_ONUMBER;
  1991.         }
  1992.         else if (!strncmp(s,"NUMBER",strlen("NUMBER"))) {
  1993.             gh->CurrentGadget->Type = GAD_NUMBER;
  1994.         }
  1995.         else if (!strncmp(s,"CYCLE",strlen("CYCLE"))) {
  1996.             gh->CurrentGadget->Type = GAD_CYCLE;
  1997.         }
  1998.         else if (!strncmp(s,"STRING",strlen("STRING"))) {
  1999.             gh->CurrentGadget->Type = GAD_STRING;
  2000.         }
  2001.         else if (!strncmp(s,"TEXT",strlen("TEXT"))) {
  2002.             gh->CurrentGadget->Type = GAD_TEXT;
  2003.         }
  2004.         else if (!strncmp(s,"MTEXT",strlen("MTEXT"))) {
  2005.             gh->CurrentGadget->Type = GAD_MTEXT;
  2006.         }
  2007.         else if (!strncmp(s,"OSTRING",strlen("OSTRING"))) {
  2008.             gh->CurrentGadget->Type = GAD_OSTRING;
  2009.         }
  2010.         else if (!strncmp(s,"CHECK",strlen("CHECK"))) {
  2011.             gh->CurrentGadget->Type = GAD_CHECK;
  2012.         }
  2013.         else if (!strncmp(s,"SLIDER",strlen("SLIDER"))) {
  2014.             gh->CurrentGadget->Type = GAD_SLIDER;
  2015.         }
  2016.         else if (!strncmp(s,"MODE",strlen("MODE"))) {
  2017.             gh->CurrentGadget->Type = GAD_MODE;
  2018.         }
  2019.         else if (!strncmp(s,"OMODE",strlen("OMODE"))) {
  2020.             gh->CurrentGadget->Type = GAD_OMODE;
  2021.         }
  2022.         else if (!strncmp(s,"FONT",strlen("FONT"))) {
  2023.             gh->CurrentGadget->Type = GAD_FONT;
  2024.         }
  2025.         else if (!strncmp(s,"OFONT",strlen("OFONT"))) {
  2026.             gh->CurrentGadget->Type = GAD_OFONT;
  2027.         }
  2028.         else if (!strncmp(s,"LIST",strlen("LIST"))) {
  2029.             gh->CurrentGadget->Type = GAD_LIST;
  2030.         }
  2031.         else if (!strncmp(s,"MLIST",strlen("MLIST"))) {
  2032.             gh->CurrentGadget->Type = GAD_MLIST;
  2033.         }
  2034.         else if (!strncmp(s,"BUTTON",strlen("BUTTON"))) {
  2035.             gh->CurrentGadget->Type = GAD_BUTTONTEXT;
  2036.         }
  2037.         else {
  2038.             pError(gh,GetMessage(MSG_ERR_UNG),s);
  2039.             while(myfgets(gh)) {
  2040.                 /* */
  2041.             }
  2042.             gh->CurrentGadget->Type = 0;
  2043.         }
  2044.         switch (gh->CurrentGadget->Type) {
  2045.         case GAD_FILE:
  2046.         case GAD_SFILE:
  2047.         case GAD_LFILE:
  2048.             GetTitle(TRUE,gh);
  2049.             GetParameter(gh);
  2050.             GetStringDefault(gh);
  2051.             GetHelp(gh);
  2052.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3 + (GADGETWIDTH + INTERWIDTH);
  2053.             temp1 = (52*8/3) + (GADGETWIDTH + INTERWIDTH);
  2054.             break;
  2055.         case GAD_OFILE:
  2056.             GetTitle(TRUE,gh);
  2057.             GetParameter(gh);
  2058.             GetStringDefault(gh);
  2059.             GetCheckDefault(gh);
  2060.             GetHelp(gh);
  2061.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3 + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2062.             temp1 = (52*8/3) + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2063.             break;
  2064.         case GAD_ONUMBER:
  2065.             GetTitle(TRUE,gh);
  2066.             GetParameter(gh);
  2067.             GetNumberDefault(gh);
  2068.             GetCheckDefault(gh);
  2069.             GetHelp(gh);
  2070.             temp = TextLength(&(gh->MyScreen->RastPort),NUMBER,strlen(NUMBER))*2/3 + (GADGETWIDTH + INTERWIDTH);
  2071.             temp1 = (10*8/3) + (GADGETWIDTH + INTERWIDTH);
  2072.             break;
  2073.         case GAD_NUMBER:
  2074.             GetTitle(TRUE,gh);
  2075.             GetParameter(gh);
  2076.             GetNumberDefault(gh);
  2077.             GetHelp(gh);
  2078.             temp = TextLength(&(gh->MyScreen->RastPort),NUMBER,strlen(NUMBER))*2/3;
  2079.             temp1 = (10*8/3);
  2080.             break;
  2081.         case GAD_CYCLE:
  2082.             if (gh->CurrentCycle) {
  2083.                 pError(gh,GetMessage(MSG_ERR_CYCLECYCLE),NULL);
  2084.             }
  2085.             else {
  2086.                 GetTitle(TRUE,gh);
  2087.                 GetHelp(gh);
  2088.                 ProcessCycle(gh);
  2089.             }
  2090.             temp = gh->rightsize;
  2091.             temp1 = gh->trightsize;
  2092.             break;
  2093.         case GAD_STRING:
  2094.             GetTitle(TRUE,gh);
  2095.             GetParameter(gh);
  2096.             GetStringDefault(gh);
  2097.             GetHelp(gh);
  2098.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3;
  2099.             temp1 = (52*8/3);
  2100.             break;
  2101.         case GAD_TEXT:
  2102.             GetTitle(TRUE,gh);
  2103.             GetStringDefault(gh);
  2104.             GetCheckDefault(gh);
  2105.             GetHelp(gh);
  2106.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3;
  2107.             temp1 = (52*8/3);
  2108.             break;
  2109.         case GAD_MTEXT:
  2110.             gh->CurrentPos = gh->buffer;
  2111.             GetStringDefault(gh);
  2112.             GetCheckDefault(gh);
  2113.             GetHelp(gh);
  2114.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3;
  2115.             temp1 = (52*8/3);
  2116.             break;
  2117.         case GAD_OSTRING:
  2118.             GetTitle(TRUE,gh);
  2119.             GetParameter(gh);
  2120.             GetStringDefault(gh);
  2121.             GetCheckDefault(gh);
  2122.             GetHelp(gh);
  2123.             temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/3 + (GADGETWIDTH + INTERWIDTH);
  2124.             temp1 = (52*8/3) + (GADGETWIDTH + INTERWIDTH);
  2125.             break;
  2126.         case GAD_CHECK:
  2127.             GetTitle(TRUE,gh);
  2128.             GetParameter(gh);
  2129.             GetNParameter(gh);
  2130.             GetCheckDefault(gh);
  2131.             GetHelp(gh);
  2132.             temp = GADGETWIDTH;
  2133.             temp1 = GADGETWIDTH;
  2134.             break;
  2135.         case GAD_SLIDER:
  2136.             GetTitle(TRUE,gh);
  2137.             GetParameter(gh);
  2138.             GetNumberDefault(gh);
  2139.             gh->CurrentGadget->Minn = gh->CurrentGadget->Defaultn;
  2140.             GetNumberDefault(gh);
  2141.             gh->CurrentGadget->Maxn = gh->CurrentGadget->Defaultn;
  2142.             GetNumberDefault(gh);
  2143.             GetHelp(gh);
  2144.             if (gh->CurrentGadget->Defaultn < gh->CurrentGadget->Minn) {
  2145.                 gh->CurrentGadget->Defaultn = gh->CurrentGadget->Minn;
  2146.             }
  2147.             if (gh->CurrentGadget->Defaultn > gh->CurrentGadget->Maxn) {
  2148.                 gh->CurrentGadget->Defaultn = gh->CurrentGadget->Maxn;
  2149.             }
  2150.             gh->CurrentGadget->Currentn = gh->CurrentGadget->Defaultn;
  2151.             gh->CurrentGadget->logMaxn = 1;
  2152.             if (gh->CurrentGadget->Maxn > 9) {
  2153.                 gh->CurrentGadget->logMaxn = 2;
  2154.                 if (gh->CurrentGadget->Maxn > 99) {
  2155.                     gh->CurrentGadget->logMaxn = 3;
  2156.                     if (gh->CurrentGadget->Maxn > 999) {
  2157.                         gh->CurrentGadget->logMaxn = 4;
  2158.                         if (gh->CurrentGadget->Maxn > 9999) {
  2159.                             gh->CurrentGadget->logMaxn = 5;
  2160.                             if (gh->CurrentGadget->Maxn > 99999) {
  2161.                                 gh->CurrentGadget->logMaxn = 6;
  2162.                             }
  2163.                         }
  2164.                     }
  2165.                 }
  2166.             }
  2167.             temp = (GADGETWIDTH * 2 + INTERWIDTH) + TextLength(&(gh->MyScreen->RastPort),NUMBER,strlen(NUMBER))* gh->CurrentGadget->logMaxn/10;
  2168.             temp1 = (GADGETWIDTH*2 + INTERWIDTH)+gh->CurrentGadget->logMaxn*8;
  2169.             break;
  2170.         case GAD_MODE:
  2171.             s += 4;
  2172.             if ((*s > '0') && (*s < '5')) {
  2173.                 gh->CurrentGadget->ModeType = *s - '0';
  2174.                 GetTitle(TRUE,gh);
  2175.                 GetParameter(gh);
  2176.                 GetStringDefault(gh);
  2177.                 GetHelp(gh);
  2178.                 temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/2 + (GADGETWIDTH + INTERWIDTH);
  2179.                 temp1 = (52*8/2) + (GADGETWIDTH + INTERWIDTH);
  2180.             }
  2181.             else {
  2182.                 pError(gh,GetMessage(MSG_ERR_MODEN),NULL);
  2183.                 temp = gh->rightsize;
  2184.                 temp1 = gh->trightsize;
  2185.             }
  2186.             break;
  2187.         case GAD_OMODE:
  2188.             s += 5;
  2189.             if ((*s > '0') && (*s < '5')) {
  2190.                 gh->CurrentGadget->ModeType = *s - '0';
  2191.                 GetTitle(TRUE,gh);
  2192.                 GetParameter(gh);
  2193.                 GetStringDefault(gh);
  2194.                 GetCheckDefault(gh);
  2195.                 GetHelp(gh);
  2196.                 temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/2 + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2197.                 temp1 = (52*8/2) + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2198.             }
  2199.             else {
  2200.                 temp = gh->rightsize;
  2201.                 temp1 = gh->trightsize;
  2202.                 pError(gh,GetMessage(MSG_ERR_OMODEN),NULL);
  2203.             }
  2204.             break;
  2205.         case GAD_FONT:
  2206.             s += 4;
  2207.             if ((*s > '0') && (*s < '3')) {
  2208.                 gh->CurrentGadget->ModeType = *s - '0';
  2209.                 GetTitle(TRUE,gh);
  2210.                 GetParameter(gh);
  2211.                 GetStringDefault(gh);
  2212.                 GetHelp(gh);
  2213.                 temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/2 + (GADGETWIDTH + INTERWIDTH);
  2214.                 temp1 = (52*8/2) + (GADGETWIDTH + INTERWIDTH);
  2215.             }
  2216.             else {
  2217.                 temp = gh->rightsize;
  2218.                 temp1 = gh->trightsize;
  2219.                 pError(gh,GetMessage(MSG_ERR_FONTN),NULL);
  2220.             }
  2221.             break;
  2222.         case GAD_OFONT:
  2223.             s += 5;
  2224.             if ((*s > '0') && (*s < '3')) {
  2225.                 gh->CurrentGadget->ModeType = *s - '0';
  2226.                 GetTitle(TRUE,gh);
  2227.                 GetParameter(gh);
  2228.                 GetStringDefault(gh);
  2229.                 GetCheckDefault(gh);
  2230.                 GetHelp(gh);
  2231.                 temp = TextLength(&(gh->MyScreen->RastPort),ALPHA,strlen(ALPHA))/2 + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2232.                 temp1 = (52*8/2) + (GADGETWIDTH * 2 + INTERWIDTH * 2);
  2233.             }
  2234.             else {
  2235.                 pError(gh,GetMessage(MSG_ERR_OFONTN),NULL);
  2236.                 temp = gh->rightsize;
  2237.                 temp1 = gh->trightsize;
  2238.             }
  2239.             break;
  2240.         case GAD_LIST:
  2241.             GetTitle(TRUE,gh);
  2242.             GetHelp(gh);
  2243.             ProcessList(gh);
  2244.             gh->numlines += gh->CurrentGadget->Lines-1;
  2245.             gh->extralist += gh->CurrentGadget->Lines-1;
  2246.             temp = gh->rightsize;
  2247.             temp1 = gh->trightsize;
  2248.             break;
  2249.         case GAD_MLIST:
  2250.             GetTitle(TRUE,gh);
  2251.             GetHelp(gh);
  2252.             ProcessMList(gh);
  2253.             gh->numlines += gh->CurrentGadget->Lines-1;
  2254.             gh->extralist += gh->CurrentGadget->Lines-1;
  2255.             temp = gh->rightsize;
  2256.             temp1 = gh->trightsize;
  2257.             break;
  2258.         case GAD_BUTTONTEXT:
  2259.             GetTitle(FALSE,gh);
  2260.             {
  2261.                 int temp2;
  2262.                 temp2 = TextLength(&(gh->MyScreen->RastPort),gh->CurrentGadget->Title,strlen(gh->CurrentGadget->Title)) + INTERWIDTH;
  2263.                 if (temp2 > gh->leftsize) {
  2264.                     gh->leftsize = temp2;
  2265.                 }
  2266.                 temp2 = strlen(gh->CurrentGadget->Title) * 8 + INTERWIDTH;
  2267.                 if (temp2 > gh->tleftsize) {
  2268.                     gh->tleftsize = temp2;
  2269.                 }
  2270.             }
  2271.             ProcessButton(gh);
  2272.             temp = gh->rightsize;
  2273.             temp1 = gh->trightsize;
  2274.             break;
  2275.         default:
  2276.             break;
  2277.         }
  2278.         if (temp > gh->rightsize) {
  2279.             gh->rightsize = temp;
  2280.         }
  2281.         if (temp1 > gh->trightsize) {
  2282.             gh->trightsize = temp1;
  2283.         }
  2284.         ++gh->numlines;
  2285.     }
  2286.     else {
  2287.         pError(gh,GetMessage(MSG_ERR_UNSPC),NULL);
  2288.     }
  2289.     gh->CurrentGadget = NULL;
  2290. }
  2291.  
  2292. void
  2293. ProcessButton(struct MPGuiHandle *gh) {
  2294.     short endfound = 0;
  2295.     short first = 1;
  2296.     BOOL Left;
  2297.     char *s;
  2298.     int width = 0;
  2299.     int twidth = 0;
  2300.     struct MyGadget *Button;
  2301.  
  2302.     Button = gh->CurrentGadget;
  2303.     if (*gh->CurrentGadget->Title) {
  2304.         Left = TRUE;
  2305.     }
  2306.     else {
  2307.         Left = FALSE;
  2308.     }
  2309.     while (!endfound && myfgets(gh)) {
  2310.         s = SkipSpace(gh->buffer);
  2311.         if (s) {
  2312.             if ('"' == *s) {
  2313.                 first = 0;
  2314.                 if (gh->CurrentGadget = (struct MyGadget *)AllocPooled(gh->MemPool,sizeof(struct MyGadget))) {
  2315.                     NewList(&(gh->CurrentGadget->VList));
  2316.                     AddTail(&(gh->GList),&(gh->CurrentGadget->GNode));
  2317.                     if (gh->CurrentCycle) {
  2318.                         gh->CurrentGadget->Activey = gh->CurrentCycleVal;
  2319.                         gh->CurrentGadget->OwnCycle = gh->CurrentCycle;
  2320.                     }
  2321.                     gh->CurrentGadget->Type = GAD_BUTTON;
  2322.                     gh->CurrentGadget->OwnButton = Button;
  2323.                     ++Button->ButtonCount;
  2324.                     GetTitle(FALSE,gh);
  2325.                     GetNumberDefault(gh);
  2326.                     gh->CurrentGadget->ButtonNo = gh->CurrentGadget->Defaultn;
  2327.                     GetHelp(gh);
  2328.                     width += TextLength(&(gh->MyScreen->RastPort),gh->CurrentGadget->Title,strlen(gh->CurrentGadget->Title)) + INTERWIDTH;
  2329.                     twidth += 8*(strlen(gh->CurrentGadget->Title) + INTERWIDTH);
  2330.                 }
  2331.                 else {
  2332.                     pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  2333.                     gh->OutOfMemory = 1;
  2334.                     return;
  2335.                 }
  2336.             }
  2337.             else {
  2338.                 if (!first) {
  2339.                     if (!strncmp(s,"ENDBUTTON",strlen("ENDBUTTON"))) {
  2340.                         width += INTERWIDTH * (Button->ButtonCount - 1);
  2341.                         twidth += INTERWIDTH * (Button->ButtonCount - 1);
  2342.                         if (Left) {
  2343.                             if (width > gh->rightsize) {
  2344.                                 gh->rightsize = width;
  2345.                             }
  2346.                             if (twidth > gh->trightsize) {
  2347.                                 gh->trightsize = twidth;
  2348.                             }
  2349.                         }
  2350.                         else {
  2351.                             if (width > gh->allsize) {
  2352.                                 gh->allsize = width;
  2353.                             }
  2354.                             if (twidth > gh->tallsize) {
  2355.                                 gh->tallsize = twidth;
  2356.                             }
  2357.                         }
  2358.                         endfound = 1;
  2359.                     }
  2360.                     else {
  2361.                         pError(gh,GetMessage(MSG_ERR_UNBUT),NULL);
  2362.                         return;
  2363.                     }
  2364.                 }
  2365.                 else {
  2366.                     pError(gh,GetMessage(MSG_ERR_FIRSTBUT),NULL);
  2367.                     while (myfgets(gh)) {
  2368.                         /* */
  2369.                     }
  2370.                 }
  2371.             }
  2372.         }
  2373.         else {
  2374.             pError(gh,GetMessage(MSG_ERR_ENDBSPC),NULL);
  2375.             return;
  2376.         }
  2377.     }
  2378.     if (!endfound) {
  2379.         pError(gh,GetMessage(MSG_ERR_ENDBEOF),NULL);
  2380.     }
  2381. }
  2382.  
  2383. void
  2384. ProcessCycle(struct MPGuiHandle *gh) {
  2385.     char *s;
  2386.     short endfound = 0;
  2387.     short first = 1;
  2388.     short StringCount = 0;
  2389.     struct MyValue *MyValue;
  2390.  
  2391.     gh->CurrentCycle = gh->CurrentGadget;
  2392.     gh->CurrentCycleVal = -1;
  2393.     while (!endfound && myfgets(gh)) {
  2394.         s = SkipSpace(gh->buffer);
  2395.         if (s) {
  2396.             if (*s == '"') {
  2397.                 first = 0;
  2398.                 if (gh->CurrentValue = (struct MyValue *)AllocPooled(gh->MemPool,sizeof(struct MyValue))) {
  2399.                     AddTail(&gh->CurrentCycle->VList,&gh->CurrentValue->VNode);
  2400.                     GetCycleTitle(gh);
  2401.                     GetCycleParameter(gh);
  2402.                     gh->CurrentValue = NULL;
  2403.                     ++StringCount;
  2404.                     ++gh->CurrentCycleVal;
  2405.                 }
  2406.                 else {
  2407.                     pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  2408.                     gh->OutOfMemory = 1;
  2409.                     return;
  2410.                 }
  2411.             }
  2412.             else {
  2413.                 if (!first) {
  2414.                     if (!strncmp(s,"ENDCYCLE",strlen("ENDCYCLE"))) {
  2415.                         GetDefCycle(gh);
  2416.                         endfound = 1;
  2417.                     }
  2418.                     else {
  2419.                         ProcessGadget(gh);
  2420.                     }
  2421.                 }
  2422.                 else {
  2423.                     pError(gh,GetMessage(MSG_ERR_FIRSTCYC),NULL);
  2424.                     while (myfgets(gh)) {
  2425.                         /* */
  2426.                     }
  2427.                 }
  2428.             }
  2429.         }
  2430.         else {
  2431.             pError(gh,GetMessage(MSG_ERR_ENDCSPC),NULL);
  2432.             return;
  2433.         }
  2434.     }
  2435.     if (!endfound) {
  2436.         pError(gh,GetMessage(MSG_ERR_ENDCEOF),NULL);
  2437.     }
  2438.     if (gh->ptr = gh->CurrentCycle->VStrings = (STRPTR *)AllocPooled(gh->MemPool,sizeof(STRPTR)*(StringCount+1))) {
  2439.         for (MyValue = (struct MyValue *)gh->CurrentCycle->VList.lh_Head;
  2440.                 MyValue->VNode.ln_Succ;
  2441.                 MyValue = (struct MyValue *)MyValue->VNode.ln_Succ) {
  2442.             *(gh->ptr) = MyValue->VNode.ln_Name;
  2443.             (gh->ptr)++;
  2444.         }
  2445.         gh->CurrentCycle->Numbery = StringCount;
  2446.     }
  2447.     else {
  2448.         pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  2449.         gh->OutOfMemory = 1;
  2450.         return;
  2451.     }
  2452.     gh->CurrentCycle = NULL;
  2453. }
  2454.  
  2455. void
  2456. ProcessList(struct MPGuiHandle *gh) {
  2457.     char *s;
  2458.     short endfound = 0;
  2459.     short first = 1;
  2460.     short StringCount = 0;
  2461.  
  2462.     while (!endfound && myfgets(gh)) {
  2463.         s = SkipSpace(gh->buffer);
  2464.         if (s) {
  2465.             if (*s == '"') {
  2466.                 first = 0;
  2467.                 if (gh->CurrentValue = (struct MyValue *)AllocPooled(gh->MemPool,sizeof(struct MyValue))) {
  2468.                     AddTail(&gh->CurrentGadget->VList,&gh->CurrentValue->VNode);
  2469.                     GetListTitle(gh);
  2470.                     GetListParameter(gh);
  2471.                     gh->CurrentValue = NULL;
  2472.                     ++StringCount;
  2473.                 }
  2474.                 else {
  2475.                     pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  2476.                     gh->OutOfMemory = 1;
  2477.                     return;
  2478.                 }
  2479.             }
  2480.             else {
  2481.                 if (!first) {
  2482.                     if (!strncmp(s,"ENDLIST",strlen("ENDLIST"))) {
  2483.                         GetDefList(gh);
  2484.                         GetDefLines(gh);
  2485.                         endfound = 1;
  2486.                     }
  2487.                 }
  2488.                 else {
  2489.                     pError(gh,GetMessage(MSG_ERR_FIRSTLIST),NULL);
  2490.                     while (myfgets(gh)) {
  2491.                         /* */
  2492.                     }
  2493.                 }
  2494.             }
  2495.         }
  2496.         else {
  2497.             pError(gh,GetMessage(MSG_ERR_ENDLSPC),NULL);
  2498.             return;
  2499.         }
  2500.     }
  2501.     if (!endfound) {
  2502.         pError(gh,GetMessage(MSG_ERR_ENDLEOF),NULL);
  2503.     }
  2504.     gh->CurrentGadget->Numbery = StringCount;
  2505. }
  2506.  
  2507. void
  2508. ProcessMList(struct MPGuiHandle *gh) {
  2509.     char *s;
  2510.     short endfound = 0;
  2511.     short first = 1;
  2512.     short StringCount = 0;
  2513.  
  2514.     while (!endfound && myfgets(gh)) {
  2515.         s = SkipSpace(gh->buffer);
  2516.         if (s) {
  2517.             if (*s == '"') {
  2518.                 first = 0;
  2519.                 if (gh->CurrentValue = (struct MyValue *)AllocPooled(gh->MemPool,sizeof(struct MyValue))) {
  2520.                     AddTail(&gh->CurrentGadget->VList,&gh->CurrentValue->VNode);
  2521.                     GetListTitle(gh);
  2522.                     GetListParameter(gh);
  2523.                     GetListNParameter(gh);
  2524.                     gh->CurrentValue = NULL;
  2525.                     ++StringCount;
  2526.                 }
  2527.                 else {
  2528.                     pError(gh,GetMessage(MSG_ERR_NOMEM),NULL);
  2529.                     gh->OutOfMemory = 1;
  2530.                     return;
  2531.                 }
  2532.             }
  2533.             else {
  2534.                 if (!first) {
  2535.                     if (!strncmp(s,"ENDMLIST",strlen("ENDMLIST"))) {
  2536.                         GetDefMList(gh);
  2537.                         GetDefLines(gh);
  2538.                         endfound = 1;
  2539.                     }
  2540.                 }
  2541.                 else {
  2542.                     pError(gh,GetMessage(MSG_ERR_FIRSTLIST),NULL);
  2543.                     while (myfgets(gh)) {
  2544.                         /* */
  2545.                     }
  2546.                 }
  2547.             }
  2548.         }
  2549.         else {
  2550.             pError(gh,GetMessage(MSG_ERR_ENDLSPC),NULL);
  2551.             return;
  2552.         }
  2553.     }
  2554.     if (!endfound) {
  2555.         pError(gh,GetMessage(MSG_ERR_ENDLEOF),NULL);
  2556.     }
  2557.     gh->CurrentGadget->Numbery = StringCount;
  2558. }
  2559.  
  2560. void
  2561. GetTitle(BOOL SetLeft,struct MPGuiHandle *gh) {
  2562.     char *s;
  2563.     int temp;
  2564.  
  2565.     gh->CurrentPos = strchr(gh->buffer,'"');
  2566.     if (gh->CurrentPos) {
  2567.         s = gh->CurrentPos + 1;
  2568.         gh->CurrentPos = strchr(s,'"');
  2569.         if (gh->CurrentPos) {
  2570.             *gh->CurrentPos = 0;
  2571.             gh->CurrentGadget->Title = mystrdup(gh,s);
  2572.             if (SetLeft) {
  2573.                 temp = TextLength(&(gh->MyScreen->RastPort),s,strlen(s));
  2574.                 if (temp > gh->leftsize) {
  2575.                     gh->leftsize = temp;
  2576.                 }
  2577.                 temp = strlen(s) * 8;
  2578.                 if (temp > gh->tleftsize) {
  2579.                     gh->tleftsize = temp;
  2580.                 }
  2581.             }
  2582.             s = strchr(gh->CurrentGadget->Title,'_');
  2583.             if (s) {
  2584.                 char c;
  2585.                 ++s;
  2586.                 c = gh->CurrentGadget->Char = toupper(*s);
  2587.                 if (c == OKCHAR) {
  2588.                     gh->NoOk = TRUE;
  2589.                 }
  2590.                 if (c == USECHAR) {
  2591.                     gh->NoUse = TRUE;
  2592.                 }
  2593.                 if (c == SAVECHAR) {
  2594.                     gh->NoSave = TRUE;
  2595.                 }
  2596.                 if (c == CANCELCHAR) {
  2597.                     gh->NoCancel = TRUE;
  2598.                 }
  2599.             }
  2600.             ++(gh->CurrentPos);
  2601.         }
  2602.         else {
  2603.             pError(gh,GetMessage(MSG_ERR_TEQ),NULL);
  2604.         }
  2605.     }
  2606.     else {
  2607.         pError(gh,GetMessage(MSG_ERR_TSQ),NULL);
  2608.     }
  2609. }
  2610.  
  2611. void
  2612. GetParameter(struct MPGuiHandle *gh) {
  2613.     char *s;
  2614.     if (gh->CurrentPos) {
  2615.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2616.         if (gh->CurrentPos) {
  2617.             s = gh->CurrentPos + 1;
  2618.             gh->CurrentPos = strchr(s,'"');
  2619.             if (gh->CurrentPos) {
  2620.                 *(gh->CurrentPos) = 0;
  2621.                 gh->CurrentGadget->Prefix = mystrdup(gh,s);
  2622.                 ++(gh->CurrentPos);
  2623.             }
  2624.             else {
  2625.                 pError(gh,GetMessage(MSG_ERR_PEQ),NULL);
  2626.             }
  2627.         }
  2628.         else {
  2629.             pError(gh,GetMessage(MSG_ERR_PSQ),NULL);
  2630.         }
  2631.     }
  2632. }
  2633.  
  2634. void
  2635. GetNParameter(struct MPGuiHandle *gh) {
  2636.     char *s;
  2637.     if (gh->CurrentPos) {
  2638.         s = strchr(gh->CurrentPos,'"');
  2639.         if (s) {
  2640.             gh->CurrentPos = s;
  2641.             s = gh->CurrentPos + 1;
  2642.             gh->CurrentPos = strchr(s,'"');
  2643.             if (gh->CurrentPos) {
  2644.                 *(gh->CurrentPos) = 0;
  2645.                 gh->CurrentGadget->NPrefix = mystrdup(gh,s);
  2646.                 ++(gh->CurrentPos);
  2647.             }
  2648.             else {
  2649.                 pError(gh,GetMessage(MSG_ERR_NPEQ),NULL);
  2650.             }
  2651.         }
  2652.     }
  2653. }
  2654.  
  2655. void
  2656. GetStringDefault(struct MPGuiHandle *gh) {
  2657.     char *s;
  2658.     if (gh->CurrentPos) {
  2659.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2660.         if (gh->CurrentPos) {
  2661.             s = gh->CurrentPos + 1;
  2662.             gh->CurrentPos = strchr(s,'"');
  2663.             if (gh->CurrentPos) {
  2664.                 *(gh->CurrentPos) = 0;
  2665.                 gh->CurrentGadget->Defaults = mystrdup(gh,s);
  2666.                 ++(gh->CurrentPos);
  2667.             }
  2668.             else {
  2669.                 pError(gh,GetMessage(MSG_ERR_DEFEQ),NULL);
  2670.             }
  2671.         }
  2672.         else {
  2673.             gh->CurrentGadget->Defaults = (char *)"";
  2674.         }
  2675.     }
  2676.     else {
  2677.         gh->CurrentGadget->Defaults = (char *)"";
  2678.     }
  2679. }
  2680.  
  2681. void
  2682. GetNumberDefault(struct MPGuiHandle *gh) {
  2683.     char *s;
  2684.     long number;
  2685.     if (gh->CurrentPos) {
  2686.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2687.         if (gh->CurrentPos) {
  2688.             s = gh->CurrentPos + 1;
  2689.             gh->CurrentPos = strchr(s,'"');
  2690.             if (gh->CurrentPos) {
  2691.                 *(gh->CurrentPos) = 0;
  2692.                 number = strtol(s,&(gh->CurrentPos),10);
  2693.                 gh->CurrentGadget->Defaultn = number;
  2694.                 ++(gh->CurrentPos);
  2695.             }
  2696.             else {
  2697.                 pError(gh,GetMessage(MSG_ERR_DEFEQ),NULL);
  2698.             }
  2699.         }
  2700.         else {
  2701.             number = 0;
  2702.             gh->CurrentGadget->Defaultn = number;
  2703.         }
  2704.     }
  2705.     else {
  2706.         number = 0;
  2707.         gh->CurrentGadget->Defaultn = number;
  2708.     }
  2709. }
  2710.  
  2711. void
  2712. GetCheckDefault(struct MPGuiHandle *gh) {
  2713.     char *s;
  2714.     short Check;
  2715.     if (gh->CurrentPos) {
  2716.         s = strpbrk(gh->CurrentPos,"YN");
  2717.         if (s && *s) {
  2718.             if (*s == 'Y') {
  2719.                 Check = 1;
  2720.                 gh->CurrentGadget->Defaultc = Check;
  2721.             }
  2722.             else {
  2723.                 Check = 0;
  2724.                 gh->CurrentGadget->Defaultc = Check;
  2725.             }
  2726.         }
  2727.         else {
  2728.             Check = 0;
  2729.             gh->CurrentGadget->Defaultc = Check;
  2730.         }
  2731.     }
  2732.     else {
  2733.         Check = 0;
  2734.         gh->CurrentGadget->Defaultc = Check;
  2735.     }
  2736.     gh->CurrentGadget->Currentc = gh->CurrentGadget->Defaultc;
  2737. }
  2738.  
  2739. void
  2740. GetDefCycle(struct MPGuiHandle *gh) {
  2741.     char *s;
  2742.     long number=0;
  2743.     long i;
  2744.     struct MyValue *MyValue;
  2745.  
  2746.     gh->CurrentPos = strchr(gh->buffer,'"');
  2747.     if (gh->CurrentPos) {
  2748.         s = gh->CurrentPos + 1;
  2749.         gh->CurrentPos = strchr(s,'"');
  2750.         if (gh->CurrentPos) {
  2751.             *(gh->CurrentPos) = 0;
  2752.             if (isdigit(*s)) {
  2753.                 number = strtol(s,&(gh->CurrentPos),10);
  2754.             }
  2755.             else {
  2756.                 i = 0;
  2757.                 for (MyValue = (struct MyValue *)(gh->CurrentCycle->VList.lh_Head);
  2758.                         MyValue->VNode.ln_Succ;
  2759.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  2760.                     if (!strcmp(s,MyValue->VNode.ln_Name)) {
  2761.                         number = i;
  2762.                     }
  2763.                     ++i;
  2764.                 }
  2765.             }
  2766.             gh->CurrentCycle->Defaulty = number;
  2767.             ++(gh->CurrentPos);
  2768.         }
  2769.         else {
  2770.             pError(gh,GetMessage(MSG_ERR_DEFEQ),NULL);
  2771.         }
  2772.     }
  2773.     else {
  2774.         number = 0;
  2775.         gh->CurrentCycle->Defaulty = number;
  2776.     }
  2777.     gh->CurrentCycle->Currenty = gh->CurrentCycle->Defaulty;
  2778. }
  2779.  
  2780. void
  2781. GetDefList(struct MPGuiHandle *gh) {
  2782.     char *s;
  2783.     long number=0;
  2784.     long i;
  2785.     struct MyValue *MyValue;
  2786.  
  2787.     gh->CurrentPos = strchr(gh->buffer,'"');
  2788.     if (gh->CurrentPos) {
  2789.         s = gh->CurrentPos + 1;
  2790.         gh->CurrentPos = strchr(s,'"');
  2791.         if (gh->CurrentPos) {
  2792.             *(gh->CurrentPos) = 0;
  2793.             if (isdigit(*s)) {
  2794.                 number = strtol(s,&(gh->CurrentPos),10);
  2795.             }
  2796.             else {
  2797.                 i = 0;
  2798.                 for (MyValue = (struct MyValue *)(gh->CurrentGadget->VList.lh_Head);
  2799.                         MyValue->VNode.ln_Succ;
  2800.                         MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  2801.                     if (!strcmp(s,MyValue->VNode.ln_Name)) {
  2802.                         number = i;
  2803.                     }
  2804.                     ++i;
  2805.                 }
  2806.             }
  2807.             gh->CurrentGadget->Defaulty = number;
  2808.             ++(gh->CurrentPos);
  2809.         }
  2810.         else {
  2811.             pError(gh,GetMessage(MSG_ERR_DEFEQ),NULL);
  2812.         }
  2813.     }
  2814.     else {
  2815.         number = 0;
  2816.         gh->CurrentGadget->Defaulty = number;
  2817.     }
  2818.     gh->CurrentGadget->Currenty = gh->CurrentGadget->Defaulty;
  2819. }
  2820.  
  2821. void
  2822. GetDefMList(struct MPGuiHandle *gh) {
  2823.     char *s;
  2824.     struct MyValue *MyValue;
  2825.  
  2826.     gh->CurrentPos = strchr(gh->buffer,'"');
  2827.     if (gh->CurrentPos) {
  2828.         s = gh->CurrentPos + 1;
  2829.         gh->CurrentPos = strchr(s,'"');
  2830.         if (gh->CurrentPos) {
  2831.             *(gh->CurrentPos) = 0;
  2832.             gh->CurrentGadget->Defaults = mystrdup(gh,s);
  2833.             for (MyValue = (struct MyValue *)(gh->CurrentGadget->VList.lh_Head);
  2834.                     MyValue->VNode.ln_Succ;
  2835.                     MyValue = (struct MyValue *)(MyValue->VNode.ln_Succ)){
  2836.                 if (strstr(s,MyValue->VNode.ln_Name)) {
  2837.                     MyValue->Selected = TRUE;
  2838.                 }
  2839.             }
  2840.             ++(gh->CurrentPos);
  2841.         }
  2842.         else {
  2843.             pError(gh,GetMessage(MSG_ERR_DEFEQ),NULL);
  2844.         }
  2845.     }
  2846.     else {
  2847.         gh->CurrentGadget->Defaults = "";
  2848.     }
  2849. }
  2850.  
  2851. void
  2852. GetDefLines(struct MPGuiHandle *gh) {
  2853.     char *s;
  2854.  
  2855.     if (gh->CurrentPos) {
  2856.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2857.         if (gh->CurrentPos) {
  2858.             s = gh->CurrentPos + 1;
  2859.             gh->CurrentPos = strchr(s,'"');
  2860.             if (gh->CurrentPos) {
  2861.                 *(gh->CurrentPos) = 0;
  2862.                 if (isdigit(*s)) {
  2863.                     gh->CurrentGadget->Lines = strtol(s,&(gh->CurrentPos),10);
  2864.                 }
  2865.                 else {
  2866.                     pError(gh,GetMessage(MSG_ERR_INVLL),NULL);
  2867.                 }
  2868.                 ++(gh->CurrentPos);
  2869.             }
  2870.             else {
  2871.                 pError(gh,GetMessage(MSG_ERR_LEQ),NULL);
  2872.             }
  2873.         }
  2874.         else {
  2875.             gh->CurrentGadget->Lines = 4;
  2876.         }
  2877.     }
  2878.     else {
  2879.         gh->CurrentGadget->Lines = 4;
  2880.     }
  2881. }
  2882.  
  2883. void
  2884. GetCycleTitle(struct MPGuiHandle *gh) {
  2885.     char *s;
  2886.     int temp;
  2887.     gh->CurrentPos = strchr(gh->buffer,'"');
  2888.     if (gh->CurrentPos) {
  2889.         s = gh->CurrentPos + 1;
  2890.         gh->CurrentPos = strchr(s,'"');
  2891.         if (gh->CurrentPos) {
  2892.             *(gh->CurrentPos) = 0;
  2893.             gh->CurrentValue->VNode.ln_Name = mystrdup(gh,s);
  2894.             temp = TextLength(&(gh->MyScreen->RastPort),s,strlen(s))+(GADGETWIDTH+INTERWIDTH);
  2895.             if (temp > gh->rightsize) {
  2896.                 gh->rightsize = temp;
  2897.             }
  2898.             temp = 8*strlen(s) + (GADGETWIDTH + INTERWIDTH);
  2899.             if (temp > gh->trightsize) {
  2900.                 gh->trightsize = temp;
  2901.             }
  2902.             ++(gh->CurrentPos);
  2903.         }
  2904.         else {
  2905.             pError(gh,GetMessage(MSG_ERR_CYCLEVEQ),NULL);
  2906.         }
  2907.     }
  2908.     else {
  2909.         pError(gh,GetMessage(MSG_ERR_CYCLEVSQ),NULL);
  2910.     }
  2911. }
  2912.  
  2913. void
  2914. GetCycleParameter(struct MPGuiHandle *gh) {
  2915.     char *s;
  2916.     if (gh->CurrentPos) {
  2917.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2918.         if (gh->CurrentPos) {
  2919.             s = gh->CurrentPos + 1;
  2920.             gh->CurrentPos = strchr(s,'"');
  2921.             if (gh->CurrentPos) {
  2922.                 *(gh->CurrentPos) = 0;
  2923.                 gh->CurrentValue->Prefix = mystrdup(gh,s);
  2924.                 ++(gh->CurrentPos);
  2925.             }
  2926.             else {
  2927.                 pError(gh,GetMessage(MSG_ERR_CYCLEPEQ),NULL);
  2928.             }
  2929.         }
  2930.         else {
  2931.             pError(gh,GetMessage(MSG_ERR_CYCLEPSQ),NULL);
  2932.         }
  2933.     }
  2934. }
  2935.  
  2936. void
  2937. GetListTitle(struct MPGuiHandle *gh) {
  2938.     char *s;
  2939.     int temp;
  2940.     gh->CurrentPos = strchr(gh->buffer,'"');
  2941.     if (gh->CurrentPos) {
  2942.         s = gh->CurrentPos + 1;
  2943.         gh->CurrentPos = strchr(s,'"');
  2944.         if (gh->CurrentPos) {
  2945.             *(gh->CurrentPos) = 0;
  2946.             gh->CurrentValue->VNode.ln_Name = mystrdup(gh,s);
  2947.             temp = TextLength(&(gh->MyScreen->RastPort),s,strlen(s))+(GADGETWIDTH+INTERWIDTH);
  2948.             if (temp > gh->rightsize) {
  2949.                 gh->rightsize = temp;
  2950.             }
  2951.             temp = 8*strlen(s) + (GADGETWIDTH + INTERWIDTH);
  2952.             if (temp > gh->trightsize) {
  2953.                 gh->trightsize = temp;
  2954.             }
  2955.             ++(gh->CurrentPos);
  2956.         }
  2957.         else {
  2958.             pError(gh,GetMessage(MSG_ERR_LISTVEQ),NULL);
  2959.         }
  2960.     }
  2961.     else {
  2962.         pError(gh,GetMessage(MSG_ERR_LISTVSQ),NULL);
  2963.     }
  2964. }
  2965.  
  2966. void
  2967. GetListParameter(struct MPGuiHandle *gh) {
  2968.     char *s;
  2969.     if (gh->CurrentPos) {
  2970.         gh->CurrentPos = strchr(gh->CurrentPos,'"');
  2971.         if (gh->CurrentPos) {
  2972.             s = gh->CurrentPos + 1;
  2973.             gh->CurrentPos = strchr(s,'"');
  2974.             if (gh->CurrentPos) {
  2975.                 *(gh->CurrentPos) = 0;
  2976.                 gh->CurrentValue->Prefix = mystrdup(gh,s);
  2977.                 ++(gh->CurrentPos);
  2978.             }
  2979.             else {
  2980.                 pError(gh,GetMessage(MSG_ERR_MLISTVPE),NULL);
  2981.             }
  2982.         }
  2983.         else {
  2984.             pError(gh,GetMessage(MSG_ERR_MLISTVPS),NULL);
  2985.         }
  2986.     }
  2987. }
  2988.  
  2989. void
  2990. GetListNParameter(struct MPGuiHandle *gh) {
  2991.     char *s;
  2992.     if (gh->CurrentPos) {
  2993.         s = strchr(gh->CurrentPos,'"');
  2994.         if (s) {
  2995.             gh->CurrentPos = s;
  2996.             s = gh->CurrentPos + 1;
  2997.             gh->CurrentPos = strchr(s,'"');
  2998.             if (gh->CurrentPos) {
  2999.                 *(gh->CurrentPos) = 0;
  3000.                 gh->CurrentValue->NPrefix = mystrdup(gh,s);
  3001.                 ++(gh->CurrentPos);
  3002.             }
  3003.             else {
  3004.                 pError(gh,GetMessage(MSG_ERR_MLISTENQ),NULL);
  3005.             }
  3006.         }
  3007.     }
  3008. }
  3009.  
  3010. void
  3011. GetHelp(struct MPGuiHandle *gh) {
  3012.     char *s;
  3013.     if (gh->CurrentPos) {
  3014.         gh->CurrentPos = strchr(gh->CurrentPos,'!');
  3015.         if (gh->CurrentPos) {
  3016.             s = gh->CurrentPos + 1;
  3017.             gh->CurrentPos = strchr(s,'!');
  3018.             if (gh->CurrentPos) {
  3019.                 *(gh->CurrentPos) = 0;
  3020.                 gh->CurrentGadget->HelpNode = mystrdup(gh,s);
  3021.                 ++(gh->CurrentPos);
  3022.                 if (*gh->CurrentPos) {
  3023.                     s = gh->CurrentPos;
  3024.                     gh->CurrentPos = strchr(s,'!');
  3025.                     if (gh->CurrentPos) {
  3026.                         *(gh->CurrentPos) = 0;
  3027.                         gh->CurrentGadget->HelpMessage = mystrdup(gh,s);
  3028.                         gh->HelpMessageB = TRUE;
  3029.                         ++(gh->CurrentPos);
  3030.                     }
  3031.                     else {
  3032.                         pError(gh,GetMessage(MSG_ERR_ENDMP),NULL);
  3033.                     }
  3034.                 }
  3035.             }
  3036.             else {
  3037.                 pError(gh,GetMessage(MSG_ERR_ENDNP),NULL);
  3038.             }
  3039.         }
  3040.     }
  3041. }
  3042.  
  3043. char
  3044. *SkipSpace(char *s) {
  3045.     while (s && *s && ((*s == ' ') || (*s == '\t'))) {
  3046.         ++s;
  3047.     }
  3048.     return s;
  3049. }
  3050.  
  3051. #define USEROK            ((struct MyGadgetPtr *)(-1))
  3052. #define USERSAVE        USEROK
  3053. #define USERCANCEL    ((struct MyGadgetPtr *)(-2))
  3054. #define USERHELP        ((struct MyGadgetPtr *)(-3))
  3055. #define USERUSE        ((struct MyGadgetPtr *)(-4))
  3056. #define USERMESSAGE    ((struct MyGadgetPtr *)(-5))
  3057.  
  3058. void
  3059. RequesterStuff(struct MPGuiHandle *gh) {
  3060.     struct MyGadgetPtr *Ptr=0;
  3061.     struct MyGadget *MyGadget=0,*LoopGadget;
  3062.     struct MyValue *val;
  3063.     short notdone = 1;
  3064.     LONG left=0;
  3065.     LONG top=0;
  3066.     BOOL relmouse=FALSE;
  3067.     BOOL doit;
  3068.     struct TagItem *tag;
  3069.     struct MyGadget *HelpGadget=NULL,*oldHelpGadget=(struct MyGadget *)-1;
  3070.     ULONG Signals;
  3071.     char *p;
  3072.     char *HelpMessage;
  3073.     int i;
  3074.  
  3075.     if (gh->VisInfo = GetVisualInfo(gh->MyScreen,NULL)) {
  3076.         if (CreateContext(&(gh->Context))) {
  3077.             if (CreateGadgets(gh)) {
  3078.                 if (tag = FindTagItem(MPG_RELMOUSE,gh->TagList)) {
  3079.                     if (tag->ti_Data) {
  3080.                         relmouse = TRUE;
  3081.                         left = gh->MyScreen->MouseX - gh->width/2;
  3082.                         if (left < 0) {
  3083.                             left = 0;
  3084.                         }
  3085.                         top = gh->MyScreen->MouseY - gh->height/2;
  3086.                         if (top < 0) {
  3087.                             top = 0;
  3088.                         }
  3089.                     }
  3090.                 }
  3091.                 gh->Zoom[0] = (USHORT)~0;
  3092.                 gh->Zoom[1] = (USHORT)~0;
  3093.                 gh->Zoom[2] = gh->TitleLength + (GADGETWIDTH * 3 + INTERWIDTH);
  3094.                 gh->Zoom[3] = gh->MyScreen->WBorTop + gh->MyScreen->Font->ta_YSize + 1;
  3095.                 if (gh->Window = OpenWindowTags(NULL,
  3096.                        WA_Flags,      WFLG_DRAGBAR|
  3097.                                      WFLG_DEPTHGADGET|
  3098.                                        WFLG_CLOSEGADGET|
  3099.                                             WFLG_SMART_REFRESH|
  3100.                                          WFLG_ACTIVATE,
  3101.                     WA_IDCMP,       BUTTONIDCMP|
  3102.                                         CHECKBOXIDCMP|
  3103.                                         INTEGERIDCMP|
  3104.                                         CYCLEIDCMP|
  3105.                                         SLIDERIDCMP|
  3106.                                         STRINGIDCMP|
  3107.                                         LISTVIEWIDCMP|
  3108.                                      IDCMP_CLOSEWINDOW|
  3109.                                       IDCMP_VANILLAKEY|
  3110.                                       IDCMP_RAWKEY|
  3111.                                       IDCMP_REFRESHWINDOW|
  3112.                                       IDCMP_GADGETHELP|
  3113.                                       (gh->MenuFunc?IDCMP_MENUPICK:0)|
  3114.                                       ((gh->MenuFunc&&gh->HelpFunc)?IDCMP_MENUHELP:0),
  3115.                        WA_Width,       gh->width,
  3116.                    WA_Height,      gh->height,
  3117.                      WA_Title,        gh->Comment,
  3118.                      WA_AutoAdjust,TRUE,
  3119.                      WA_PubScreen,    gh->MyScreen,
  3120.                      WA_Gadgets,    gh->Context,
  3121.                      WA_Zoom,         gh->Zoom,
  3122.                      relmouse?WA_Left:TAG_IGNORE,    left,
  3123.                      relmouse?WA_Top:TAG_IGNORE,    top,
  3124.                      WA_MenuHelp,    gh->HelpFunc?TRUE:FALSE,
  3125.                      WA_NewLookMenus,TRUE,
  3126.                      gh->Check ? WA_Checkmark: TAG_IGNORE,    gh->Check,
  3127.                      gh->Amiga ? WA_AmigaKey : TAG_IGNORE,    gh->Amiga,
  3128.                      TAG_END)) {
  3129.                     // Enable gadget Help
  3130.                     HelpControl(gh->Window,HC_GADGETHELP);
  3131.                     if (gh->NewMenu) {
  3132.                         if (gh->Menu = CreateMenus( gh->NewMenu, TAG_DONE )) {
  3133.                             LayoutMenus( gh->Menu, gh->VisInfo, 
  3134.                                             GTMN_NewLookMenus,TRUE,
  3135.                                             gh->Check ? GTMN_Checkmark : TAG_IGNORE, gh->Check,
  3136.                                             gh->Amiga ? GTMN_AmigaKey : TAG_IGNORE, gh->Amiga,
  3137.                                             TAG_DONE );
  3138.                             SetMenuStrip( gh->Window, gh->Menu);
  3139.                         }
  3140.                     }
  3141.                     GT_RefreshWindow(gh->Window,NULL);
  3142.                     if (gh->CHelp && gh->HelpFunc) {
  3143.                         if (gh->HelpNode) {
  3144.                             MyCallHookPkt(gh,gh->HelpFunc,gh->HelpNode,NULL);
  3145.                         }
  3146.                     }
  3147.                     while (notdone) {
  3148.                      Signals = Wait((1L << gh->Window->UserPort->mp_SigBit) |
  3149.                                           (gh->Signals));
  3150.                      if (Signals & gh->Signals) {
  3151.                         if (gh->SignalFunc) {
  3152.                             notdone = MyCallHookPkt(gh,gh->SignalFunc,(APTR)Signals,NULL);
  3153.                             if (!notdone) {
  3154.                                 gh->result[0] = 0;
  3155.                             }
  3156.                         }
  3157.                      }
  3158.                      else {
  3159.                         while (gh->IntuiMsg = GT_GetIMsg(gh->Window->UserPort)) {
  3160.                             switch (gh->IntuiMsg->Class) {
  3161.                             case IDCMP_MENUPICK:
  3162.                                 if (gh->MenuFunc) {
  3163.                                     notdone = MyCallHookPkt(gh,gh->MenuFunc,gh->IntuiMsg,gh->Menu);
  3164.                                 }
  3165.                                 break;
  3166.                             case IDCMP_MENUHELP:
  3167.                                 if (gh->MenuFunc && gh->HelpFunc) {
  3168.                                     MyCallHookPkt(gh,gh->MenuFunc,gh->IntuiMsg,gh->Menu);
  3169.                                 }
  3170.                                 break;
  3171.                             case IDCMP_RAWKEY:
  3172.                                 if (gh->IntuiMsg->Code == 0x5f) {
  3173.                                     if (gh->HelpFunc) {
  3174.                                         if (HelpGadget && HelpGadget->HelpNode) {
  3175.                                             MyCallHookPkt(gh,gh->HelpFunc,HelpGadget->HelpNode,NULL);
  3176.                                         }
  3177.                                         else {
  3178.                                             if (gh->HelpNode) {
  3179.                                                 MyCallHookPkt(gh,gh->HelpFunc,gh->HelpNode,NULL);
  3180.                                             }
  3181.                                         }
  3182.                                     }
  3183.                                 }
  3184.                                 break;
  3185.                             case IDCMP_GADGETHELP:
  3186.                                  if (gh->IntuiMsg->IAddress == NULL) {
  3187.                                      HelpGadget = NULL;
  3188.                                      HelpMessage = gh->HelpMessage;
  3189.                                  }
  3190.                                  else {
  3191.                                      if (gh->IntuiMsg->IAddress == gh->Window) {
  3192.                                          HelpGadget = NULL;
  3193.                                          HelpMessage = gh->HelpMessage;
  3194.                                      }
  3195.                                      else {
  3196.                                          if (!(((struct Gadget *)gh->IntuiMsg->IAddress)->GadgetType & GTYP_SYSGADGET)) {    // Not a system gadget
  3197.                                             Ptr = (struct MyGadgetPtr *)((struct Gadget *)gh->IntuiMsg->IAddress)->UserData;
  3198.                                             if (Ptr == USERSAVE && gh->Prefs) {
  3199.                                                 HelpGadget = NULL;
  3200.                                                 HelpMessage = GetMessage(MSG_HELPSAVE);
  3201.                                             }
  3202.                                             else if (Ptr == USEROK && !gh->Prefs) {
  3203.                                                 HelpGadget = NULL;
  3204.                                                 HelpMessage = GetMessage(MSG_HELPOK);
  3205.                                             }
  3206.                                             else if (Ptr == USERUSE) {
  3207.                                                 HelpGadget = NULL;
  3208.                                                 HelpMessage = GetMessage(MSG_HELPUSE);
  3209.                                             }
  3210.                                             else if (Ptr == USERCANCEL && gh->Prefs) {
  3211.                                                 HelpGadget = NULL;
  3212.                                                 HelpMessage = GetMessage(MSG_HELPCANCELP);
  3213.                                             }
  3214.                                             else if (Ptr == USERCANCEL && !gh->Prefs) {
  3215.                                                 HelpGadget = NULL;
  3216.                                                 HelpMessage = GetMessage(MSG_HELPCANCELR);
  3217.                                             }
  3218.                                             else if (Ptr == USERHELP) {
  3219.                                                 HelpGadget = NULL;
  3220.                                                 HelpMessage = GetMessage(MSG_HELPHELPB);
  3221.                                             }
  3222.                                             else if (Ptr == USERMESSAGE) {
  3223.                                                 HelpGadget = NULL;
  3224.                                                 HelpMessage = GetMessage(MSG_HELPHELPG);
  3225.                                             }
  3226.                                             else if (Ptr) {
  3227.                                                 HelpGadget = Ptr->MyGadget;
  3228.                                                 HelpMessage = HelpGadget->HelpMessage;
  3229.                                             }
  3230.                                             else {
  3231.                                                 HelpGadget = NULL;
  3232.                                                  HelpMessage = gh->HelpMessage;
  3233.                                             }
  3234.                                          }
  3235.                                          else {
  3236.                                              switch (((struct Gadget *)gh->IntuiMsg->IAddress)->GadgetType & GTYP_SYSTYPEMASK) {
  3237.                                              case GTYP_WDRAGGING:
  3238.                                                  HelpMessage = GetMessage(MSG_HELPDRAG);
  3239.                                                  break;
  3240.                                              case GTYP_WUPFRONT:
  3241.                                                  HelpMessage = GetMessage(MSG_HELPFRONT);
  3242.                                                  break;
  3243.                                              case GTYP_WDOWNBACK:
  3244.                                                  HelpMessage = GetMessage(MSG_HELPZOOM);
  3245.                                                  break;
  3246.                                              case GTYP_CLOSE:
  3247.                                                  if (gh->Prefs) {
  3248.                                                      HelpMessage = GetMessage(MSG_HELPCANCELP);
  3249.                                                  }
  3250.                                                  else {
  3251.                                                     HelpMessage = GetMessage(MSG_HELPCANCELR);
  3252.                                                  }
  3253.                                                  break;
  3254.                                              default:
  3255.                                                  HelpMessage = gh->HelpMessage;
  3256.                                                  break;
  3257.                                              }
  3258.                                              HelpGadget = NULL;
  3259.                                          }
  3260.                                      }
  3261.                                  }
  3262.                                  if (!HelpMessage) {
  3263.                                      HelpMessage = gh->HelpMessage;
  3264.                                 }
  3265.                                 if (gh->HelpMessageB) {
  3266.                                     GT_SetGadgetAttrs(gh->HelpGadget,gh->Window,NULL,
  3267.                                                             GTTX_Text,HelpMessage,
  3268.                                                             TAG_END);
  3269.                                 }
  3270.                                  if (gh->CHelp && gh->HelpFunc) {
  3271.                                      if (oldHelpGadget != HelpGadget) {
  3272.                                         if (HelpGadget && HelpGadget->HelpNode) {
  3273.                                             MyCallHookPkt(gh,gh->HelpFunc,HelpGadget->HelpNode,NULL);
  3274.                                         }
  3275.                                         else {
  3276.                                             if (gh->HelpNode) {
  3277.                                                 MyCallHookPkt(gh,gh->HelpFunc,gh->HelpNode,NULL);
  3278.                                             }
  3279.                                         }
  3280.                                         oldHelpGadget = HelpGadget;
  3281.                                     }
  3282.                                 }
  3283.                                 break;
  3284.                             case IDCMP_REFRESHWINDOW:
  3285.                                 GT_BeginRefresh(gh->Window);
  3286.                                 GT_EndRefresh(gh->Window,TRUE);
  3287.                                 break;
  3288.                             case IDCMP_CLOSEWINDOW:
  3289.                                 notdone = 0;
  3290.                                 break;
  3291.                             case IDCMP_VANILLAKEY:
  3292.                             case IDCMP_GADGETUP:
  3293.                                 if ((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3294.                                      (gh->IntuiMsg->Code == 0x5F)) {    // Help key in string
  3295.                                     Ptr = (struct MyGadgetPtr *)((struct Gadget *)gh->IntuiMsg->IAddress)->UserData;
  3296.                                     // Cant be Ok, Help, Cancel, Save, Use
  3297.                                     HelpGadget = Ptr->MyGadget;
  3298.                                     if (gh->HelpFunc) {
  3299.                                         if (HelpGadget && HelpGadget->HelpNode) {
  3300.                                             MyCallHookPkt(gh,gh->HelpFunc,HelpGadget->HelpNode,NULL);
  3301.                                         }
  3302.                                         else {
  3303.                                             if (gh->HelpNode) {
  3304.                                                 MyCallHookPkt(gh,gh->HelpFunc,gh->HelpNode,NULL);
  3305.                                             }
  3306.                                         }
  3307.                                     }
  3308.                                     ActivateGadget((struct Gadget *)gh->IntuiMsg->IAddress,gh->Window,NULL);
  3309.                                     doit = FALSE;
  3310.                                 }
  3311.                                 else {
  3312.                                     if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3313.                                         doit = FALSE;
  3314.                                         if ((gh->IntuiMsg->Code == 0x1B) && !gh->Prefs) {
  3315.                                             Ptr = USERCANCEL;
  3316.                                             notdone = 0;
  3317.                                         }
  3318.                                         if (!gh->NoButtons) {
  3319.                                             if (!gh->NoOk && (toupper(gh->IntuiMsg->Code) == OKCHAR) && !gh->Prefs) {
  3320.                                                 doit = TRUE;
  3321.                                                 Ptr = USEROK;
  3322.                                             }
  3323.                                             else if (!gh->NoSave && (toupper(gh->IntuiMsg->Code) == SAVECHAR) && gh->Prefs) {
  3324.                                                 doit = TRUE;
  3325.                                                 Ptr = USERSAVE;
  3326.                                                 gh->Response = MPG_SAVE;
  3327.                                             }
  3328.                                             else if (!gh->NoUse && (toupper(gh->IntuiMsg->Code) == USECHAR) && gh->Prefs) {
  3329.                                                 doit = TRUE;
  3330.                                                 Ptr = USERUSE;
  3331.                                                 gh->Response = MPG_USE;
  3332.                                             }
  3333.                                             else if (!gh->NoCancel && toupper(gh->IntuiMsg->Code) == CANCELCHAR) {
  3334.                                                 notdone = 0;
  3335.                                             }
  3336.                                         }
  3337.                                         if (notdone && !doit) {
  3338.                                             for (LoopGadget = (struct MyGadget *)(gh->GList.lh_Head);
  3339.                                                     LoopGadget->GNode.ln_Succ;
  3340.                                                     LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)) {
  3341.                                                 if (toupper(gh->IntuiMsg->Code) == LoopGadget->Char) {
  3342.                                                     doit = TRUE;
  3343.                                                     Ptr = &(LoopGadget->Ptr1);
  3344.                                                 }
  3345.                                             }
  3346.                                         }
  3347.                                     }
  3348.                                     else {
  3349.                                         Ptr = (struct MyGadgetPtr *)((struct Gadget *)gh->IntuiMsg->IAddress)->UserData;
  3350.                                         doit = TRUE;
  3351.                                         if (Ptr == USERSAVE) {
  3352.                                             gh->Response = MPG_SAVE;
  3353.                                         }
  3354.                                         else {
  3355.                                             if (Ptr == USERUSE) {
  3356.                                                 gh->Response = MPG_USE;
  3357.                                             }
  3358.                                         }
  3359.                                     }
  3360.                                     if (Ptr == USERCANCEL) {    // Cancel gadget
  3361.                                         notdone = 0;
  3362.                                         doit = FALSE;
  3363.                                     }
  3364.                                     else {
  3365.                                         if (Ptr == USERHELP) {    // Help gadget
  3366.                                             if (gh->HelpFunc && gh->HelpNode) {
  3367.                                                 MyCallHookPkt(gh,gh->HelpFunc,gh->HelpNode,NULL);
  3368.                                             }
  3369.                                             doit = FALSE;
  3370.                                         }
  3371.                                     }
  3372.                                 }
  3373.                                 if (((Ptr == USERSAVE) || (Ptr == USERUSE)) && doit) {
  3374.                                     MPGuiCurrentAttrs(gh);
  3375.                                     notdone = 0;
  3376.                                 }
  3377.                                 else {
  3378.                                     if (doit) {
  3379.                                         MyGadget = Ptr->MyGadget;
  3380.                                         if (MyGadget->OwnCycle) {
  3381.                                             if (MyGadget->OwnCycle->Currenty != MyGadget->Activey) {
  3382.                                                 doit = FALSE;
  3383.                                             }
  3384.                                         }
  3385.                                     }
  3386.                                     if (doit) {
  3387.                                         switch (MyGadget->Type) {
  3388.                                         case GAD_FILE:
  3389.                                         case GAD_LFILE:
  3390.                                         case GAD_SFILE:
  3391.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3392.                                                  (!(gh->IntuiMsg->Qualifier & IEQUALIFIER_RSHIFT))) {
  3393.                                                 ActivateGadget(MyGadget->Gadget1,gh->Window,NULL);
  3394.                                             }
  3395.                                             else {
  3396.                                                 if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) ||
  3397.                                                      (Ptr->Number == 2)) {
  3398.                                                     GT_GetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3399.                                                             GTST_String,&p,
  3400.                                                             TAG_END);
  3401.                                                     if (GetAFile(gh,p,
  3402.                                                          (MyGadget->Type == GAD_LFILE)?GetMessage(MSG_SELECTINPUT):
  3403.                                                          (MyGadget->Type == GAD_SFILE)?GetMessage(MSG_SELECTOUTPUT):
  3404.                                                          GetMessage(MSG_SELECTFILE),
  3405.                                                          (MyGadget->Type == GAD_SFILE)?FRF_DOSAVEMODE:0,
  3406.                                                          (MyGadget->Type == GAD_LFILE)?GetMessage(MSG_INPUT):
  3407.                                                          (MyGadget->Type == GAD_SFILE)?GetMessage(MSG_OUTPUT):
  3408.                                                          GetMessage(MSG_SELECT))) {
  3409.                                                         GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3410.                                                             GTST_String,gh->TempFileName,
  3411.                                                             TAG_END);
  3412.                                                     }
  3413.                                                 }
  3414.                                             }
  3415.                                             break;
  3416.                                         case GAD_OFILE:
  3417.                                             if (((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3418.                                                   (!(gh->IntuiMsg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)))) ||
  3419.                                                  ((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3420.                                                   (Ptr->Number == 1))) {
  3421.                                                 MyGadget->Currentc = !MyGadget->Currentc;
  3422.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3423.                                                         GTCB_Checked, MyGadget->Currentc,
  3424.                                                         TAG_END);
  3425.                                                 GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3426.                                                         GA_Disabled,!MyGadget->Currentc,
  3427.                                                         TAG_END);
  3428.                                                 GT_SetGadgetAttrs(MyGadget->Gadget3,gh->Window,NULL,
  3429.                                                         GA_Disabled,!MyGadget->Currentc,
  3430.                                                         TAG_END);
  3431.                                                 if (MyGadget->Currentc) {
  3432.                                                     ActivateGadget(MyGadget->Gadget2,gh->Window,NULL);
  3433.                                                 }
  3434.                                             }
  3435.                                             else {
  3436.                                                 if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3437.                                                      (gh->IntuiMsg->Qualifier & IEQUALIFIER_LSHIFT)) {
  3438.                                                     if (MyGadget->Currentc) {
  3439.                                                         ActivateGadget(MyGadget->Gadget2,gh->Window,NULL);
  3440.                                                     }
  3441.                                                 }
  3442.                                                 else {
  3443.                                                     if (((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3444.                                                          (Ptr->Number == 3)) ||
  3445.                                                         ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3446.                                                           (gh->IntuiMsg->Qualifier & IEQUALIFIER_RSHIFT) &&
  3447.                                                           (MyGadget->Currentc))) {
  3448.                                                         GT_GetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3449.                                                                 GTST_String,&p,
  3450.                                                                 TAG_END);
  3451.                                                         if (GetAFile(gh,p,
  3452.                                                              GetMessage(MSG_SELECTFILE),0,GetMessage(MSG_SELECT))) {
  3453.                                                             GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3454.                                                                 GTST_String,gh->TempFileName,
  3455.                                                                 TAG_END);
  3456.                                                         }
  3457.                                                     }
  3458.                                                 }
  3459.                                             }
  3460.                                             break;
  3461.                                         case GAD_MODE:
  3462.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) ||
  3463.                                                   (Ptr->Number == 2)) {
  3464.                                                 GT_GetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3465.                                                         GTTX_Text,&p,
  3466.                                                         TAG_END);
  3467.                                                 if (GetAMode(gh,MyGadget,p,
  3468.                                                         GetMessage(MSG_SELECTMODE))) {
  3469.                                                     GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3470.                                                         GTTX_Text,gh->TempFileName,
  3471.                                                         TAG_END);
  3472.                                                 }
  3473.                                             }
  3474.                                             break;
  3475.                                         case GAD_OMODE:
  3476.                                         case GAD_OFONT:
  3477.                                             if (((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3478.                                                   (!(gh->IntuiMsg->Qualifier & IEQUALIFIER_RSHIFT))) ||
  3479.                                                  ((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3480.                                                   (Ptr->Number == 1))) {
  3481.                                                 MyGadget->Currentc = !MyGadget->Currentc;
  3482.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3483.                                                         GTCB_Checked, MyGadget->Currentc,
  3484.                                                         TAG_END);
  3485.                                                 GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3486.                                                         GA_Disabled,!MyGadget->Currentc,
  3487.                                                         TAG_END);
  3488.                                                 GT_SetGadgetAttrs(MyGadget->Gadget3,gh->Window,NULL,
  3489.                                                         GA_Disabled,!MyGadget->Currentc,
  3490.                                                         TAG_END);
  3491.                                             }
  3492.                                             else {
  3493.                                                 if (((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3494.                                                      (Ptr->Number == 3)) ||
  3495.                                                     ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3496.                                                       (gh->IntuiMsg->Qualifier & IEQUALIFIER_RSHIFT) &&
  3497.                                                       (MyGadget->Currentc))) {
  3498.                                                     GT_GetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3499.                                                             GTTX_Text,&p,
  3500.                                                             TAG_END);
  3501.                                                     switch (MyGadget->Type) {
  3502.                                                     case GAD_OMODE:
  3503.                                                         if (GetAMode(gh,MyGadget,p,
  3504.                                                                 GetMessage(MSG_SELECTMODE))) {
  3505.                                                             GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3506.                                                                 GTTX_Text,gh->TempFileName,
  3507.                                                                 TAG_END);
  3508.                                                         }
  3509.                                                         break;
  3510.                                                     case GAD_OFONT:
  3511.                                                         if (GetAFont(gh,MyGadget,p,
  3512.                                                                 GetMessage(MSG_SELECTFONT))) {
  3513.                                                             GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3514.                                                                 GTTX_Text,gh->TempFileName,
  3515.                                                                 TAG_END);
  3516.                                                         }
  3517.                                                         break;
  3518.                                                     }
  3519.                                                 }
  3520.                                             }
  3521.                                             break;
  3522.                                         case GAD_FONT:
  3523.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) ||
  3524.                                                   (Ptr->Number == 2)) {
  3525.                                                 GT_GetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3526.                                                         GTTX_Text,&p,
  3527.                                                         TAG_END);
  3528.                                                 if (GetAFont(gh,MyGadget,p,
  3529.                                                         GetMessage(MSG_SELECTFONT))) {
  3530.                                                     GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3531.                                                         GTTX_Text,gh->TempFileName,
  3532.                                                         TAG_END);
  3533.                                                 }
  3534.                                             }
  3535.                                             break;
  3536.                                         case GAD_ONUMBER:
  3537.                                         case GAD_OSTRING:
  3538.                                             if (((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3539.                                                   (!(gh->IntuiMsg->Qualifier & IEQUALIFIER_LSHIFT))) ||
  3540.                                                  ((gh->IntuiMsg->Class == IDCMP_GADGETUP) &&
  3541.                                                   (Ptr->Number == 1))) {
  3542.                                                 MyGadget->Currentc = !MyGadget->Currentc;
  3543.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3544.                                                         GTCB_Checked, MyGadget->Currentc,
  3545.                                                         TAG_END);
  3546.                                                 GT_SetGadgetAttrs(MyGadget->Gadget2,gh->Window,NULL,
  3547.                                                         GA_Disabled,!MyGadget->Currentc,
  3548.                                                         TAG_END);
  3549.                                                 if (MyGadget->Currentc) {
  3550.                                                     ActivateGadget(MyGadget->Gadget2,gh->Window,NULL);
  3551.                                                 }
  3552.                                             }
  3553.                                             else {
  3554.                                                 if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3555.                                                     if (MyGadget->Currentc) {
  3556.                                                         ActivateGadget(MyGadget->Gadget2,gh->Window,NULL);
  3557.                                                     }
  3558.                                                 }
  3559.                                             }
  3560.                                             break;
  3561.                                         case GAD_NUMBER:
  3562.                                         case GAD_STRING:
  3563.                                             if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3564.                                                 ActivateGadget(MyGadget->Gadget1,gh->Window,NULL);
  3565.                                             }
  3566.                                             break;
  3567.                                         case GAD_LIST:
  3568.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3569.                                                  (gh->IntuiMsg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))) {
  3570.                                                 if (!MyGadget->Currenty) {
  3571.                                                     MyGadget->Currenty = MyGadget->Numbery - 1;
  3572.                                                 }
  3573.                                                 else {
  3574.                                                     MyGadget->Currenty -= 1;
  3575.                                                 }
  3576.                                             }
  3577.                                             else {
  3578.                                                 if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3579.                                                     ++MyGadget->Currenty;
  3580.                                                     if (MyGadget->Currenty == MyGadget->Numbery) {
  3581.                                                         MyGadget->Currenty = 0;
  3582.                                                     }
  3583.                                                 }
  3584.                                                 else {
  3585.                                                     MyGadget->Currenty = gh->IntuiMsg->Code;
  3586.                                                 }
  3587.                                             }
  3588.                                             GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3589.                                                             GTLV_Selected, MyGadget->Currenty,
  3590.                                                             GTLV_MakeVisible, MyGadget->Currenty,
  3591.                                                             TAG_END);
  3592.                                             break;
  3593.                                         case GAD_MLIST:
  3594.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3595.                                                  !(gh->IntuiMsg->Qualifier & IEQUALIFIER_RSHIFT)) {
  3596.                                                 if (gh->IntuiMsg->Qualifier & IEQUALIFIER_LSHIFT) {
  3597.                                                     if (!MyGadget->Currenty) {
  3598.                                                         MyGadget->Currenty = MyGadget->Numbery - 1;
  3599.                                                     }
  3600.                                                     else {
  3601.                                                         MyGadget->Currenty -= 1;
  3602.                                                     }
  3603.                                                 }
  3604.                                                 else {
  3605.                                                     ++MyGadget->Currenty;
  3606.                                                     if (MyGadget->Currenty == MyGadget->Numbery) {
  3607.                                                         MyGadget->Currenty = 0;
  3608.                                                     }
  3609.                                                 }
  3610.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3611.                                                             GTLV_Selected, MyGadget->Currenty,
  3612.                                                             GTLV_MakeVisible, MyGadget->Currenty,
  3613.                                                             TAG_END);
  3614.                                             }
  3615.                                             else {
  3616.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3617.                                                                 GTLV_Labels, -1,
  3618.                                                                 TAG_END);
  3619.                                                 if (gh->IntuiMsg->Class != IDCMP_VANILLAKEY) {
  3620.                                                     MyGadget->Currenty = gh->IntuiMsg->Code;
  3621.                                                 }
  3622.                                                 val = (struct MyValue *)MyGadget->VList.lh_Head;
  3623.                                                 for (i=0; (i < MyGadget->Currenty); i++) {
  3624.                                                     val = (struct MyValue *)val->VNode.ln_Succ;
  3625.                                                 }
  3626.                                                 if (val->Selected) {
  3627.                                                     val->Selected = FALSE;
  3628.                                                 }
  3629.                                                 else {
  3630.                                                     val->Selected = TRUE;
  3631.                                                 }
  3632.                                                 GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3633.                                                                 GTLV_Labels,    &(MyGadget->VList),
  3634.                                                                 GTLV_Selected, MyGadget->Currenty,
  3635.                                                                 TAG_END);
  3636.                                             }
  3637.                                             break;
  3638.                                         case GAD_CYCLE:
  3639.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3640.                                                  (gh->IntuiMsg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))) {
  3641.                                                 if (!MyGadget->Currenty) {
  3642.                                                     MyGadget->Currenty = MyGadget->Numbery - 1;
  3643.                                                 }
  3644.                                                 else {
  3645.                                                     MyGadget->Currenty -= 1;
  3646.                                                 }
  3647.                                             }
  3648.                                             else {
  3649.                                                 if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3650.                                                     ++MyGadget->Currenty;
  3651.                                                     if (MyGadget->Currenty == MyGadget->Numbery) {
  3652.                                                         MyGadget->Currenty = 0;
  3653.                                                     }
  3654.                                                 }
  3655.                                                 else {
  3656.                                                     MyGadget->Currenty = gh->IntuiMsg->Code;
  3657.                                                 }
  3658.                                             }
  3659.                                             GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3660.                                                         GTCY_Active, MyGadget->Currenty,
  3661.                                                         TAG_END);
  3662.                                             for (LoopGadget = (struct MyGadget *)(gh->GList.lh_Head);
  3663.                                                     LoopGadget->GNode.ln_Succ;
  3664.                                                     LoopGadget = (struct MyGadget *)(LoopGadget->GNode.ln_Succ)){
  3665.                                                 if (MyGadget == LoopGadget->OwnCycle) {
  3666.                                                     GT_SetGadgetAttrs(LoopGadget->Gadget1,gh->Window,NULL,
  3667.                                                             GA_Disabled,MyGadget->Currenty != LoopGadget->Activey,
  3668.                                                             TAG_END);
  3669.                                                     if (LoopGadget->Gadget2) {
  3670.                                                         GT_SetGadgetAttrs(LoopGadget->Gadget2,gh->Window,NULL,
  3671.                                                                 GA_Disabled,(MyGadget->Currenty != LoopGadget->Activey) ||
  3672.                                                                                 (((LoopGadget->Type == GAD_ONUMBER) ||
  3673.                                                                                   (LoopGadget->Type == GAD_OSTRING) ||
  3674.                                                                                   (LoopGadget->Type == GAD_OFILE)) && (!LoopGadget->Currentc)),
  3675.                                                                 TAG_END);
  3676.                                                     }
  3677.                                                     if (LoopGadget->Gadget3) {
  3678.                                                         GT_SetGadgetAttrs(LoopGadget->Gadget3,gh->Window,NULL,
  3679.                                                                 GA_Disabled,(MyGadget->Currenty != LoopGadget->Activey) ||
  3680.                                                                                   (((LoopGadget->Type == GAD_OFILE) ||
  3681.                                                                                     (LoopGadget->Type == GAD_OFONT) ||
  3682.                                                                                     (LoopGadget->Type == GAD_OMODE)) && (!LoopGadget->Currentc)),
  3683.                                                                 TAG_END);
  3684.                                                     }
  3685.                                                 }
  3686.                                             }
  3687.                                             break;
  3688.                                         case GAD_CHECK:
  3689.                                             MyGadget->Currentc = !MyGadget->Currentc;
  3690.                                             GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3691.                                                     GTCB_Checked, MyGadget->Currentc,
  3692.                                                     TAG_END);
  3693.                                             break;
  3694.                                         case GAD_SLIDER:
  3695.                                             if ((gh->IntuiMsg->Class == IDCMP_VANILLAKEY) &&
  3696.                                                  (gh->IntuiMsg->Qualifier & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT))) {
  3697.                                                 if (MyGadget->Currentn > MyGadget->Minn) {
  3698.                                                     MyGadget->Currentn -= 1;
  3699.                                                 }
  3700.                                             }
  3701.                                             else {
  3702.                                                 if (gh->IntuiMsg->Class == IDCMP_VANILLAKEY) {
  3703.                                                     if (MyGadget->Currentn < MyGadget->Maxn) {
  3704.                                                         MyGadget->Currentn += 1;
  3705.                                                     }
  3706.                                                 }
  3707.                                                 else {
  3708.                                                     MyGadget->Currentn = gh->IntuiMsg->Code;
  3709.                                                 }
  3710.                                             }
  3711.                                             GT_SetGadgetAttrs(MyGadget->Gadget1,gh->Window,NULL,
  3712.                                                         GTSL_Level, MyGadget->Currentn,
  3713.                                                         TAG_END);
  3714.                                             break;
  3715.                                         case GAD_BUTTON:
  3716.                                             if (gh->ButtonFunc) {
  3717.                                                 notdone = MyCallHookPkt(gh,gh->ButtonFunc,gh,(APTR)MyGadget->ButtonNo);
  3718.                                             }
  3719.                                             break;
  3720.                                         }
  3721.                                     }
  3722.                                 }
  3723.                                 break;
  3724.                             default:
  3725.                                 break;
  3726.                             }
  3727.                             GT_ReplyIMsg(gh->IntuiMsg);
  3728.                         }
  3729.                      }
  3730.                     }
  3731.                     if (gh->Menu) {
  3732.                         ClearMenuStrip(gh->Window);
  3733.                         FreeMenus(gh->Menu);
  3734.                     }
  3735.                     CloseWindow(gh->Window);
  3736.                 }
  3737.             }
  3738.             FreeGadgets(gh->Context);
  3739.         }
  3740.         FreeVisualInfo(gh->VisInfo);
  3741.     }
  3742. }
  3743.  
  3744. /* Creates all the gadgets for a requester
  3745.  * Returns:        TRUE if everything worked
  3746.  */
  3747. BOOL
  3748. CreateGadgets(struct MPGuiHandle *gh) {
  3749.     struct MyGadget *MyGadget;
  3750.     struct Gadget *Gadget;
  3751.     struct NewGadget NewGadget = {
  3752.         0,0,
  3753.         0,0,
  3754.         NULL,
  3755.         NULL,
  3756.         PLACETEXT_IN,
  3757.         NULL,
  3758.         NULL
  3759.     };
  3760.     int CancelSize;
  3761.     int temp;
  3762.     int tleft = 0;
  3763.     BOOL InButton = FALSE;
  3764.     int ButtonNo = 0;    // Number of this gadget in ButtonText
  3765.     long ButtonWidth = 0;    // Set to get fixed width buttons
  3766.  
  3767.     if (gh->UseTopaz) {
  3768.         CancelSize = gh->XSize*strlen(GetMessage(MSG__CANCEL));
  3769.     }
  3770.     else {
  3771.         CancelSize = TextLength(&(gh->MyScreen->RastPort),GetMessage(MSG__CANCEL),strlen(GetMessage(MSG__CANCEL)));
  3772.     }
  3773.     if ((CancelSize + (gh->interwidth)) > gh->rightsize) {
  3774.         gh->rightsize = CancelSize+gh->interwidth;
  3775.     }
  3776.     if ((CancelSize) > gh->leftsize) {
  3777.         gh->leftsize = CancelSize;
  3778.     }
  3779.     if ((gh->HelpFunc && gh->HelpNode) || (gh->Prefs)) {
  3780.         if (((CancelSize + (gh->interwidth))*2) > gh->rightsize) {
  3781.             gh->rightsize = (CancelSize+gh->interwidth)*2;
  3782.         }
  3783.     }
  3784.     gh->width = gh->leftsize + gh->rightsize + (gh->interwidth * 2) +
  3785.               gh->MyScreen->WBorLeft + gh->MyScreen->WBorRight;
  3786.     if ((gh->TitleLength + (GADGETWIDTH * 3 + gh->interwidth)) > gh->width) {
  3787.         gh->width = gh->TitleLength + (GADGETWIDTH * 3 + gh->interwidth);
  3788.         temp = gh->width - gh->leftsize - gh->rightsize - (gh->interwidth * 2) -
  3789.                  gh->MyScreen->WBorLeft - gh->MyScreen->WBorRight;
  3790.         gh->leftsize += temp/2;
  3791.         gh->rightsize += temp/2;
  3792.     }
  3793.     Gadget = gh->Context;
  3794.     gh->height = gh->MyScreen->WBorTop + gh->MyScreen->Font->ta_YSize + 1;
  3795.     NewGadget.ng_Height = gh->MyTextAttr->ta_YSize + 4;
  3796.     NewGadget.ng_VisualInfo = gh->VisInfo;
  3797.     NewGadget.ng_TextAttr = gh->MyTextAttr;
  3798.     NewGadget.ng_Flags = PLACETEXT_LEFT;
  3799.     if (gh->HelpMessageB) {
  3800.         gh->height += gh->interheight;
  3801.         NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth;
  3802.         NewGadget.ng_Width = gh->rightsize + gh->leftsize;
  3803.         NewGadget.ng_TopEdge = gh->height;
  3804.         NewGadget.ng_UserData = (APTR)USERMESSAGE;
  3805.         gh->HelpGadget = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  3806.                                         GTTX_Text, gh->HelpMessage,
  3807.                                         GTTX_Border, TRUE,
  3808.                                         TAG_END);
  3809.         gh->height += gh->MyTextAttr->ta_YSize + 2;
  3810.     }
  3811.     for (MyGadget = (struct MyGadget *)gh->GList.lh_Head;
  3812.             MyGadget->GNode.ln_Succ && Gadget;
  3813.             MyGadget = (struct MyGadget *)MyGadget->GNode.ln_Succ) {
  3814.         if (InButton &&
  3815.              (MyGadget->Type != GAD_BUTTON)) {
  3816.             gh->height += gh->MyTextAttr->ta_YSize + 2;
  3817.             InButton = FALSE;
  3818.         }
  3819.         if (!InButton) {
  3820.             gh->height += gh->interheight;
  3821.         }
  3822.         NewGadget.ng_TopEdge = gh->height;
  3823.         switch (MyGadget->Type) {
  3824.         case GAD_FILE:
  3825.         case GAD_LFILE:
  3826.         case GAD_SFILE:
  3827.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3828.             MyGadget->Ptr1.MyGadget = MyGadget;
  3829.             MyGadget->Ptr1.Number = 1;
  3830.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3831.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3832.             NewGadget.ng_Width = gh->rightsize - (gh->interwidth/2 + GADGETWIDTH);
  3833.             NewGadget.ng_GadgetText = MyGadget->Title;
  3834.             MyGadget->Gadget1 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  3835.                                         GTST_String, MyGadget->Defaults,
  3836.                                         GTST_MaxChars, 256,
  3837.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3838.                                         GT_Underscore, '_',
  3839.                                         STRINGA_ExitHelp, TRUE,
  3840.                                         TAG_END);
  3841.             NewGadget.ng_LeftEdge += NewGadget.ng_Width + gh->interwidth/2;
  3842.             MyGadget->Ptr2.MyGadget = MyGadget;
  3843.             MyGadget->Ptr2.Number = 2;
  3844.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  3845.             NewGadget.ng_Width = GADGETWIDTH;
  3846.             NewGadget.ng_Flags = PLACETEXT_IN;
  3847.             NewGadget.ng_GadgetText = (char *)"«";
  3848.             MyGadget->Gadget2 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  3849.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3850.                                         TAG_END);
  3851.             NewGadget.ng_Flags = PLACETEXT_LEFT;
  3852.             break;
  3853.         case GAD_MODE:
  3854.         case GAD_FONT:
  3855.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3856.             MyGadget->Ptr1.MyGadget = MyGadget;
  3857.             MyGadget->Ptr1.Number = 1;
  3858.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3859.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3860.             NewGadget.ng_Width = gh->rightsize - (gh->interwidth/2 + GADGETWIDTH);
  3861.             NewGadget.ng_GadgetText = MyGadget->Title;
  3862.             MyGadget->Gadget1 = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  3863.                                         GTTX_Text, MyGadget->Defaults,
  3864.                                         GTTX_Border, TRUE,
  3865.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3866.                                         GT_Underscore, '_',
  3867.                                         TAG_END);
  3868.             NewGadget.ng_LeftEdge += NewGadget.ng_Width + gh->interwidth/2;
  3869.             MyGadget->Ptr2.MyGadget = MyGadget;
  3870.             MyGadget->Ptr2.Number = 2;
  3871.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  3872.             NewGadget.ng_Width = GADGETWIDTH;
  3873.             NewGadget.ng_Flags = PLACETEXT_IN;
  3874.             NewGadget.ng_GadgetText = (char *)"«";
  3875.             MyGadget->Gadget2 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  3876.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3877.                                         TAG_END);
  3878.             NewGadget.ng_Flags = PLACETEXT_LEFT;
  3879.             break;
  3880.         case GAD_OMODE:
  3881.         case GAD_OFONT:
  3882.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3883.             MyGadget->Ptr1.MyGadget = MyGadget;
  3884.             MyGadget->Ptr1.Number = 1;
  3885.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3886.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3887.             NewGadget.ng_Width = GADGETWIDTH;
  3888.             NewGadget.ng_GadgetText = MyGadget->Title;
  3889.             MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  3890.                                         GTCB_Checked, MyGadget->Currentc,
  3891.                                         GTCB_Scaled, TRUE,
  3892.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3893.                                         GT_Underscore, '_',
  3894.                                         TAG_END);
  3895.             MyGadget->Ptr2.MyGadget = MyGadget;
  3896.             MyGadget->Ptr2.Number = 2;
  3897.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  3898.             NewGadget.ng_LeftEdge += gh->interwidth/2 + GADGETWIDTH;
  3899.             NewGadget.ng_Width = gh->rightsize - ((gh->interwidth/2 + GADGETWIDTH) * 2);
  3900.             NewGadget.ng_GadgetText = NULL;
  3901.             MyGadget->Gadget2 = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  3902.                                         GTTX_Text, MyGadget->Defaults,
  3903.                                         GTTX_Border, TRUE,
  3904.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  3905.                                         GT_Underscore, '_',
  3906.                                         TAG_END);
  3907.             NewGadget.ng_LeftEdge += NewGadget.ng_Width + gh->interwidth/2;
  3908.             MyGadget->Ptr3.MyGadget = MyGadget;
  3909.             MyGadget->Ptr3.Number = 3;
  3910.             NewGadget.ng_UserData = &(MyGadget->Ptr3);
  3911.             NewGadget.ng_Width = GADGETWIDTH;
  3912.             NewGadget.ng_Flags = PLACETEXT_IN;
  3913.             NewGadget.ng_GadgetText = (char *)"«";
  3914.             MyGadget->Gadget3 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  3915.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  3916.                                         TAG_END);
  3917.             NewGadget.ng_Flags = PLACETEXT_LEFT;
  3918.             break;
  3919.         case GAD_OFILE:
  3920.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3921.             MyGadget->Ptr1.MyGadget = MyGadget;
  3922.             MyGadget->Ptr1.Number = 1;
  3923.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3924.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3925.             NewGadget.ng_Width = GADGETWIDTH;
  3926.             NewGadget.ng_GadgetText = MyGadget->Title;
  3927.             MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  3928.                                         GTCB_Checked, MyGadget->Currentc,
  3929.                                         GTCB_Scaled, TRUE,
  3930.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3931.                                         GT_Underscore, '_',
  3932.                                         TAG_END);
  3933.             MyGadget->Ptr2.MyGadget = MyGadget;
  3934.             MyGadget->Ptr2.Number = 2;
  3935.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  3936.             NewGadget.ng_LeftEdge += gh->interwidth/2 + GADGETWIDTH;
  3937.             NewGadget.ng_Width = gh->rightsize - ((gh->interwidth/2 + GADGETWIDTH) * 2);
  3938.             NewGadget.ng_GadgetText = NULL;
  3939.             MyGadget->Gadget2 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  3940.                                         GTST_String, MyGadget->Defaults,
  3941.                                         GTST_MaxChars, 256,
  3942.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  3943.                                         STRINGA_ExitHelp, TRUE,
  3944.                                         TAG_END);
  3945.             NewGadget.ng_LeftEdge += NewGadget.ng_Width + gh->interwidth/2;
  3946.             MyGadget->Ptr3.MyGadget = MyGadget;
  3947.             MyGadget->Ptr3.Number = 3;
  3948.             NewGadget.ng_UserData = &(MyGadget->Ptr3);
  3949.             NewGadget.ng_Width = GADGETWIDTH;
  3950.             NewGadget.ng_Flags = PLACETEXT_IN;
  3951.             NewGadget.ng_GadgetText = (char *)"«";
  3952.             MyGadget->Gadget3 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  3953.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  3954.                                         TAG_END);
  3955.             NewGadget.ng_Flags = PLACETEXT_LEFT;
  3956.             break;
  3957.         case GAD_ONUMBER:
  3958.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3959.             MyGadget->Ptr1.MyGadget = MyGadget;
  3960.             MyGadget->Ptr1.Number = 1;
  3961.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3962.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3963.             NewGadget.ng_Width = GADGETWIDTH;
  3964.             NewGadget.ng_GadgetText = MyGadget->Title;
  3965.             MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  3966.                                         GTCB_Checked, MyGadget->Currentc,
  3967.                                         GTCB_Scaled, TRUE,
  3968.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3969.                                         GT_Underscore, '_',
  3970.                                         TAG_END);
  3971.             MyGadget->Ptr2.MyGadget = MyGadget;
  3972.             MyGadget->Ptr2.Number = 2;
  3973.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  3974.             NewGadget.ng_LeftEdge += gh->interwidth/2 + GADGETWIDTH;
  3975.             NewGadget.ng_Width = gh->rightsize - (GADGETWIDTH + gh->interwidth/2);
  3976.             NewGadget.ng_GadgetText = NULL;
  3977.             MyGadget->Gadget2 = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  3978.                                         GTIN_Number, MyGadget->Defaultn,
  3979.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  3980.                                         STRINGA_ExitHelp, TRUE,
  3981.                                         TAG_END);
  3982.             break;
  3983.         case GAD_NUMBER:
  3984.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  3985.             MyGadget->Ptr1.MyGadget = MyGadget;
  3986.             MyGadget->Ptr1.Number = 1;
  3987.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  3988.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  3989.             NewGadget.ng_Width = gh->rightsize;
  3990.             NewGadget.ng_GadgetText = MyGadget->Title;
  3991.             MyGadget->Gadget1 = Gadget = CreateGadget(INTEGER_KIND,Gadget,&NewGadget,
  3992.                                         GTIN_Number, MyGadget->Defaultn,
  3993.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  3994.                                         GT_Underscore, '_',
  3995.                                         STRINGA_ExitHelp, TRUE,
  3996.                                         TAG_END);
  3997.             break;
  3998.         case GAD_CYCLE:
  3999.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4000.             MyGadget->Ptr1.MyGadget = MyGadget;
  4001.             MyGadget->Ptr1.Number = 1;
  4002.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4003.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4004.             NewGadget.ng_Width = gh->rightsize;
  4005.             NewGadget.ng_GadgetText = MyGadget->Title;
  4006.             MyGadget->Gadget1 = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  4007.                                         GTCY_Labels, MyGadget->VStrings,
  4008.                                         GTCY_Active, MyGadget->Currenty,
  4009.                                         GT_Underscore, '_',
  4010.                                         TAG_END);
  4011.             break;
  4012.         case GAD_STRING:
  4013.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4014.             MyGadget->Ptr1.MyGadget = MyGadget;
  4015.             MyGadget->Ptr1.Number = 1;
  4016.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4017.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4018.             NewGadget.ng_Width = gh->rightsize;
  4019.             NewGadget.ng_GadgetText = MyGadget->Title;
  4020.             MyGadget->Gadget1 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  4021.                                         GTST_String, MyGadget->Defaults,
  4022.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4023.                                         GT_Underscore, '_',
  4024.                                         STRINGA_ExitHelp, TRUE,
  4025.                                         TAG_END);
  4026.             break;
  4027.         case GAD_TEXT:
  4028.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4029.             MyGadget->Ptr1.MyGadget = MyGadget;
  4030.             MyGadget->Ptr1.Number = 1;
  4031.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4032.             if (*MyGadget->Title) {
  4033.                 NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4034.                 NewGadget.ng_Width = gh->rightsize;
  4035.             }
  4036.             else {
  4037.                 NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + tleft;
  4038.                 NewGadget.ng_Width = gh->rightsize + gh->leftsize;
  4039.             }
  4040.             NewGadget.ng_GadgetText = MyGadget->Title;
  4041.             MyGadget->Gadget1 = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  4042.                                         GTTX_Text, MyGadget->Defaults,
  4043.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4044.                                         GT_Underscore, '_',
  4045.                                         GTTX_Border, TRUE,
  4046.                                         GTTX_Justification, MyGadget->Currentc?GTJ_CENTER:GTJ_LEFT,
  4047.                                         TAG_END);
  4048.             break;
  4049.         case GAD_MTEXT:
  4050.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4051.             MyGadget->Ptr1.MyGadget = MyGadget;
  4052.             MyGadget->Ptr1.Number = 1;
  4053.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4054.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + tleft;
  4055.             NewGadget.ng_Width = gh->rightsize + gh->leftsize;
  4056.             NewGadget.ng_GadgetText = "";
  4057.             MyGadget->Gadget1 = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  4058.                                         GTTX_Text, MyGadget->Defaults,
  4059.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4060.                                         GT_Underscore, '_',
  4061.                                         GTTX_Border, FALSE,
  4062.                                         GTTX_Justification, MyGadget->Currentc?GTJ_CENTER:GTJ_LEFT,
  4063.                                         TAG_END);
  4064.             break;
  4065.         case GAD_OSTRING:
  4066.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4067.             MyGadget->Ptr1.MyGadget = MyGadget;
  4068.             MyGadget->Ptr1.Number = 1;
  4069.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4070.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4071.             NewGadget.ng_Width = GADGETWIDTH;
  4072.             NewGadget.ng_GadgetText = MyGadget->Title;
  4073.             MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  4074.                                         GTCB_Checked, MyGadget->Currentc,
  4075.                                         GTCB_Scaled, TRUE,
  4076.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4077.                                         GT_Underscore, '_',
  4078.                                         TAG_END);
  4079.             MyGadget->Ptr2.MyGadget = MyGadget;
  4080.             MyGadget->Ptr2.Number = 2;
  4081.             NewGadget.ng_UserData = &(MyGadget->Ptr2);
  4082.             NewGadget.ng_LeftEdge += gh->interwidth/2 + GADGETWIDTH;
  4083.             NewGadget.ng_Width = gh->rightsize - (GADGETWIDTH + gh->interwidth/2);
  4084.             NewGadget.ng_GadgetText = NULL;
  4085.             MyGadget->Gadget2 = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  4086.                                         GTST_String, MyGadget->Defaults,
  4087.                                         GA_Disabled,MyGadget->Currentc ? (MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE) : TRUE,
  4088.                                         STRINGA_ExitHelp, TRUE,
  4089.                                         TAG_END);
  4090.             break;
  4091.         case GAD_CHECK:
  4092.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4093.             MyGadget->Ptr1.MyGadget = MyGadget;
  4094.             MyGadget->Ptr1.Number = 1;
  4095.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4096.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4097.             NewGadget.ng_Width = GADGETWIDTH;
  4098.             NewGadget.ng_GadgetText = MyGadget->Title;
  4099.             MyGadget->Gadget1 = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  4100.                                         GTCB_Checked, MyGadget->Currentc,
  4101.                                         GTCB_Scaled, TRUE,
  4102.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4103.                                         GT_Underscore, '_',
  4104.                                         TAG_END);
  4105.             break;
  4106.         case GAD_SLIDER:
  4107.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4108.             MyGadget->Ptr1.MyGadget = MyGadget;
  4109.             MyGadget->Ptr1.Number = 1;
  4110.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4111.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4112.             NewGadget.ng_Width = gh->rightsize - 
  4113.                                         (gh->UseTopaz ? (gh->XSize * MyGadget->logMaxn) : (TextLength(&(gh->MyScreen->RastPort),NUMBER,strlen(NUMBER))* MyGadget->logMaxn/10))
  4114.                                         - gh->interwidth;
  4115.             NewGadget.ng_GadgetText = MyGadget->Title;
  4116.             MyGadget->Gadget1 = Gadget = CreateGadget(SLIDER_KIND,Gadget,&NewGadget,
  4117.                                         GTSL_Min, MyGadget->Minn,
  4118.                                         GTSL_Max, MyGadget->Maxn,
  4119.                                         GTSL_Level, MyGadget->Defaultn,
  4120.                                         GTSL_MaxLevelLen, MyGadget->logMaxn,
  4121.                                         GTSL_MaxPixelLen, gh->UseTopaz ? (gh->XSize*MyGadget->logMaxn+2) : (TextLength(&(gh->MyScreen->RastPort),"8",1)* MyGadget->logMaxn + 2),
  4122.                                         GTSL_LevelFormat, "%ld",
  4123.                                         GTSL_LevelPlace, PLACETEXT_RIGHT,
  4124.                                         GA_RelVerify, TRUE,
  4125.                                         PGA_Freedom, LORIENT_HORIZ,
  4126.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4127.                                         GT_Underscore, '_',
  4128.                                         TAG_END);
  4129.             break;
  4130.         case GAD_LIST:
  4131.         case GAD_MLIST:
  4132.             temp = NewGadget.ng_Height;
  4133.             NewGadget.ng_GadgetText = MyGadget->Title;
  4134.             NewGadget.ng_Height = (MyGadget->Lines * gh->MyTextAttr->ta_YSize) + 4;
  4135.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4136.             MyGadget->Ptr1.MyGadget = MyGadget;
  4137.             MyGadget->Ptr1.Number = 1;
  4138.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4139.             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4140.             NewGadget.ng_Width = gh->rightsize;
  4141.             MyGadget->Gadget1 = Gadget = CreateGadget(LISTVIEW_KIND,Gadget,&NewGadget,
  4142.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4143.                                         GTLV_MakeVisible, MyGadget->Currenty,
  4144.                                         GTLV_Labels, &(MyGadget->VList),
  4145.                                         GTLV_ShowSelected, NULL,
  4146.                                         GTLV_Selected, MyGadget->Currenty,
  4147.                                         GT_Underscore, '_',
  4148.                                         (GAD_MLIST==MyGadget->Type)?GTLV_CallBack:TAG_IGNORE, (ULONG)&HookList,
  4149.                                         TAG_END);
  4150.             gh->height += NewGadget.ng_Height - 2;
  4151.             NewGadget.ng_Height = temp;
  4152.             break;
  4153.         case GAD_BUTTONTEXT:
  4154.             InButton = TRUE;
  4155.             ButtonNo = 0;
  4156.             checkleft(gh,NewGadget.ng_Height,&(NewGadget.ng_TopEdge),&tleft);
  4157.             if (*MyGadget->Title) {    
  4158.                 NewGadget.ng_GadgetText = "";
  4159.                 MyGadget->Ptr1.MyGadget = MyGadget;
  4160.                 MyGadget->Ptr1.Number = 1;
  4161.                 NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4162.                 NewGadget.ng_LeftEdge = max(gh->MyScreen->WBorLeft + gh->interwidth + tleft - INTERWIDTH,0);
  4163.                 NewGadget.ng_Width = gh->leftsize;
  4164.                 MyGadget->Gadget1 = Gadget = Gadget = CreateGadget(TEXT_KIND,Gadget,&NewGadget,
  4165.                                         GTTX_Text, MyGadget->Title,
  4166.                                         GTTX_Border, FALSE,
  4167.                                         GTTX_Justification, GTJ_RIGHT,
  4168.                                         GTTX_Clipped, TRUE,
  4169.                                         TAG_END);
  4170.                 NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft;
  4171.             }
  4172.             else {
  4173.                 NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + tleft;
  4174.             }
  4175.             if (MyGadget->ButtonCount > 1) {
  4176.                 struct MyGadget *gad1;
  4177.                 int MaxWidth = 0;
  4178.                 int t;
  4179.                 for (gad1 = (struct MyGadget *)MyGadget->GNode.ln_Succ;
  4180.                       gad1->GNode.ln_Succ && (GAD_BUTTON == gad1->Type);
  4181.                       gad1 = (struct MyGadget *)gad1->GNode.ln_Succ) {
  4182.                     if (gh->UseTopaz) {
  4183.                         t = gh->XSize*strlen(gad1->Title) + INTERWIDTH;
  4184.                     }
  4185.                     else {
  4186.                         t = TextLength(&(gh->MyScreen->RastPort),gad1->Title,strlen(gad1->Title)) + INTERWIDTH;
  4187.                     }
  4188.                     if (t > MaxWidth) {
  4189.                         MaxWidth = t;
  4190.                     }
  4191.                 }
  4192.                 t = (MaxWidth + gh->interwidth) * MyGadget->ButtonCount - gh->interwidth;
  4193.                 if (*MyGadget->Title) {
  4194.                     if (t <= gh->rightsize) {
  4195.                         ButtonWidth = MaxWidth;
  4196.                     }
  4197.                     else {
  4198.                         ButtonWidth = 0;
  4199.                     }
  4200.                 }
  4201.                 else {
  4202.                     if (t <= (gh->rightsize+gh->leftsize)) {
  4203.                         ButtonWidth = MaxWidth;
  4204.                     }
  4205.                     else {
  4206.                         ButtonWidth = 0;
  4207.                     }
  4208.                 }
  4209.             }
  4210.             break;
  4211.         case GAD_BUTTON:
  4212.             NewGadget.ng_GadgetText = MyGadget->Title;
  4213.             MyGadget->Ptr1.MyGadget = MyGadget;
  4214.             MyGadget->Ptr1.Number = 1;
  4215.             NewGadget.ng_UserData = &(MyGadget->Ptr1);
  4216.             if (MyGadget->OwnButton->ButtonCount > 1) {
  4217.                 if (ButtonWidth) {
  4218.                     NewGadget.ng_Width = ButtonWidth;
  4219.                 }
  4220.                 else {
  4221.                     if (gh->UseTopaz) {
  4222.                         NewGadget.ng_Width = gh->XSize*strlen(MyGadget->Title) + INTERWIDTH;
  4223.                     }
  4224.                     else {
  4225.                         NewGadget.ng_Width = TextLength(&(gh->MyScreen->RastPort),MyGadget->Title,strlen(MyGadget->Title)) + INTERWIDTH;
  4226.                     }
  4227.                 }
  4228.             }
  4229.             else {
  4230.                 if (*MyGadget->OwnButton->Title) {
  4231.                     NewGadget.ng_Width = gh->rightsize;
  4232.                 }
  4233.                 else {
  4234.                     NewGadget.ng_Width = gh->rightsize + gh->leftsize;
  4235.                 }
  4236.             }
  4237.             if (ButtonNo) {
  4238.                 if (MyGadget->OwnButton->ButtonCount == 2) {
  4239.                     NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize +
  4240.                                                     gh->rightsize + tleft - NewGadget.ng_Width;
  4241.                 }
  4242.                 else if (MyGadget->OwnButton->ButtonCount == 3) {
  4243.                     if (1 == ButtonNo) {
  4244.                         if (*MyGadget->OwnButton->Title) {
  4245.                             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize + tleft +
  4246.                                                             (gh->rightsize - NewGadget.ng_Width)/2;
  4247.                         }
  4248.                         else {
  4249.                             NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + tleft +
  4250.                                                             (gh->leftsize + gh->rightsize - NewGadget.ng_Width)/2;
  4251.                         }
  4252.                     }
  4253.                     else if (2 == ButtonNo) {
  4254.                         NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth + gh->leftsize +
  4255.                                                         gh->rightsize + tleft - NewGadget.ng_Width;
  4256.                     }
  4257.                 }
  4258.             }
  4259.             NewGadget.ng_GadgetText = MyGadget->Title;
  4260.             NewGadget.ng_Flags = PLACETEXT_IN;
  4261.             MyGadget->Gadget1 = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  4262.                                         GA_Disabled, MyGadget->OwnCycle ?((MyGadget->OwnCycle->Currenty == MyGadget->Activey) ? FALSE : TRUE ) : FALSE,
  4263.                                         GT_Underscore, '_',
  4264.                                         TAG_END);
  4265.             NewGadget.ng_Flags = PLACETEXT_LEFT;
  4266.             NewGadget.ng_LeftEdge += NewGadget.ng_Width + gh->interwidth;
  4267.             ++ButtonNo;
  4268.             break;
  4269.         }
  4270.         if (!InButton) {
  4271.             if ((MyGadget->Type != GAD_LIST) &&
  4272.                  (MyGadget->Type != GAD_MLIST)) {
  4273.                 gh->height += gh->MyTextAttr->ta_YSize + 2;
  4274.             }
  4275.         }
  4276.     }
  4277.     if (InButton) {
  4278.         gh->height += gh->MyTextAttr->ta_YSize + 2;
  4279.     }
  4280.     if (gh->Bottom) {
  4281.         gh->height = gh->Bottom;
  4282.     }
  4283.     gh->height += gh->interheight*2;
  4284.     NewGadget.ng_Flags = PLACETEXT_IN;
  4285.     if (!gh->NoButtons && Gadget) {
  4286.         NewGadget.ng_TopEdge = gh->height;
  4287.         NewGadget.ng_UserData = (APTR)USERSAVE;
  4288.         NewGadget.ng_LeftEdge = gh->MyScreen->WBorLeft + gh->interwidth;
  4289.         NewGadget.ng_Width = CancelSize;
  4290.         if (gh->Prefs) {
  4291.             NewGadget.ng_GadgetText = (gh->NoSave?GetMessage(MSG_SAVE):GetMessage(MSG__SAVE));
  4292.         }
  4293.         else {
  4294.             NewGadget.ng_GadgetText = (gh->NoOk?GetMessage(MSG_OK):GetMessage(MSG__OK));
  4295.         }
  4296.         Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  4297.                                 GT_Underscore, '_',
  4298.                                 TAG_END);
  4299.         if (Gadget) {
  4300.             if (gh->Prefs) {
  4301.                 NewGadget.ng_UserData = (APTR)USERUSE;
  4302.                 NewGadget.ng_LeftEdge = (gh->width - CancelSize)/2;
  4303.                 NewGadget.ng_GadgetText = (gh->NoUse?GetMessage(MSG_USE):GetMessage(MSG__USE));
  4304.                 Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  4305.                                         GT_Underscore, '_',
  4306.                                         TAG_END);
  4307.             }
  4308.             else {
  4309.                 if (gh->HelpFunc && gh->HelpNode) {
  4310.                     NewGadget.ng_UserData = (APTR)USERHELP;
  4311.                     NewGadget.ng_LeftEdge = (gh->width - CancelSize)/2;
  4312.                     NewGadget.ng_GadgetText = GetMessage(MSG_HELP);
  4313.                     Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  4314.                                             TAG_END);
  4315.                 }
  4316.             }
  4317.             if (Gadget) {
  4318.                 NewGadget.ng_UserData = (APTR)USERCANCEL;
  4319.                 NewGadget.ng_LeftEdge = gh->width - gh->interwidth - gh->MyScreen->WBorRight - CancelSize;
  4320.                 NewGadget.ng_GadgetText = (gh->NoCancel?GetMessage(MSG_CANCEL):GetMessage(MSG__CANCEL));
  4321.                 Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  4322.                                         GT_Underscore, '_',
  4323.                                         TAG_END);
  4324.             }
  4325.         }
  4326.         gh->height += gh->MyTextAttr->ta_YSize + 2 + gh->MyScreen->WBorBottom + gh->interheight;
  4327.     }
  4328.     else {
  4329.         gh->height += gh->MyScreen->WBorBottom;
  4330.     }
  4331.     return (BOOL)Gadget;
  4332. }
  4333.  
  4334. static void
  4335. checkleft(struct MPGuiHandle *gh, int addheight, short *curgh, int *tleft) {
  4336.     if ((gh->height + gh->MyScreen->WBorBottom + gh->interheight + addheight +
  4337.           (gh->NoButtons?0:(gh->MyTextAttr->ta_YSize + 2 + gh->interheight))) > gh->MyScreen->Height) {
  4338.         if ((gh->height + addheight) > gh->Bottom) {
  4339.             gh->Bottom = gh->height;
  4340.         }
  4341.         gh->height = gh->MyScreen->WBorTop + gh->MyScreen->Font->ta_YSize + 1 + gh->interheight;
  4342.         *curgh = gh->height;
  4343.         *tleft += gh->leftsize + gh->rightsize + gh->interwidth;
  4344.         gh->width += gh->leftsize + gh->rightsize + gh->interwidth;
  4345.         if (gh->width > gh->MyScreen->Width) {
  4346.             gh->width -= gh->interwidth;
  4347.             *tleft -= gh->interwidth;
  4348.         }
  4349.         if (gh->width > gh->MyScreen->Width) {
  4350.             gh->rightsize -= (gh->width - gh->MyScreen->Width);
  4351.             gh->width = gh->MyScreen->Width;
  4352.         }
  4353.     }
  4354.     return;
  4355. }
  4356.  
  4357. /* Shows ASL file requester for a file
  4358.  * name    : current file name
  4359.  * Prompt: Title
  4360.  * flags    : e.g. for save flag
  4361.  * Returns: TRUE if file selected, name is TempFileName
  4362.  */
  4363. BOOL
  4364. GetAFile(struct MPGuiHandle *gh,const UBYTE *name,const char *Prompt,ULONG flags,char *positive) {
  4365.     char TempName[257];
  4366.     char TempDir[257];
  4367.  
  4368.     if (name && *name) {
  4369.         strncpy(TempDir,name,(size_t)(PathPart((char *)name) - name));
  4370.         TempDir[PathPart((char *)name)-name]=0;
  4371.         strcpy(TempName,FilePart((char *)name));
  4372.     }
  4373.     else {
  4374.         TempDir[0]=0;
  4375.         TempName[0]=0;
  4376.     }
  4377.     // Show requesters
  4378.     DisableWindow(gh);
  4379.     if (AslRequestTags((APTR) gh->filereq,
  4380.                             ASLFR_TitleText,(Tag) Prompt,
  4381.                             ASLFR_Flags1,flags,
  4382.                             ASLFR_InitialDrawer, (Tag) TempDir,
  4383.                             ASLFR_InitialFile,(Tag) TempName,
  4384.                             ASLFR_Window, gh->Window,
  4385.                             ASLFR_RejectIcons, TRUE,
  4386.                             ASLFR_PositiveText, positive,
  4387.                             ASLFR_IntuiMsgFunc, &(gh->RefreshHook),
  4388.                             TAG_DONE)) {
  4389.         // rejoin name
  4390.         strncpy(gh->TempFileName,gh->filereq->fr_Drawer,256);
  4391.         AddPart(gh->TempFileName,gh->filereq->fr_File,256);
  4392.         EnableWindow(gh);
  4393.         return TRUE;
  4394.     }
  4395.     else {
  4396.     EnableWindow(gh);
  4397.     return FALSE;
  4398.     }
  4399. }
  4400.  
  4401. /* Shows ASL file requester for a font
  4402.  * name    : current font name
  4403.  * Prompt: Title
  4404.  * Returns: TRUE if font selected, constructed name is gh->TempFileName
  4405.  */
  4406. BOOL
  4407. GetAFont(struct MPGuiHandle *gh,struct MyGadget *mg,const UBYTE *name,const char *Prompt) {
  4408.     char TempName[257];
  4409.     struct FontRequester *req;
  4410.  
  4411.     if (name && *name) {
  4412.         strcpy(TempName,name);
  4413.     }
  4414.     else {
  4415.         TempName[0]=0;
  4416.     }
  4417.     // Show requesters
  4418.     DisableWindow(gh);
  4419.     if (req = AllocAslRequest(ASL_FontRequest,NULL)) {
  4420.         if (AslRequestTags(req,
  4421.                             ASLFO_Window, gh->Window,
  4422.                             ASLFO_TitleText, Prompt,
  4423.                             ASLFO_InitialName, TempName,
  4424.                             ASLFO_InitialSize, 8,    //??
  4425.                             ASLFO_FixedWidthOnly, (mg->ModeType > 1),
  4426.                             ASLFO_PositiveText,GetMessage(MSG_SELECT),
  4427.                             ASLFO_IntuiMsgFunc, &(gh->RefreshHook),
  4428.                             TAG_END)) {
  4429.             strcpy(gh->TempFileName,req->fo_Attr.ta_Name);
  4430.             if (strlen(gh->TempFileName) > 5) {
  4431.                 if (!stricmp(&(gh->TempFileName[strlen(gh->TempFileName)-5]),".font")) {
  4432.                     gh->TempFileName[strlen(gh->TempFileName)-5] = 0;
  4433.                 }
  4434.             }
  4435.             FreeAslRequest(req);
  4436.             EnableWindow(gh);
  4437.             return TRUE;
  4438.         }
  4439.         else {
  4440.             FreeAslRequest(req);
  4441.             EnableWindow(gh);
  4442.             return FALSE;
  4443.         }
  4444.     }
  4445.     else {
  4446.         return FALSE;
  4447.     }
  4448. }
  4449.  
  4450. /* Shows ASL file requester for a font
  4451.  * name    : current font name
  4452.  * Prompt: Title
  4453.  * Returns: TRUE if file selected, name is TempFileName
  4454.  */
  4455. BOOL
  4456. GetAMode(struct MPGuiHandle *gh,struct MyGadget *mg,const UBYTE *name,const char *Prompt) {
  4457.     char TempName[257];
  4458.  
  4459.     if (name && *name) {
  4460.         strcpy(TempName,name);
  4461.     }
  4462.     else {
  4463.         TempName[0]=0;
  4464.     }
  4465.     // Show requesters
  4466.     DisableWindow(gh);
  4467.     {
  4468.         ULONG id = (ULONG)INVALID_ID;
  4469.         ULONG myid = (ULONG)INVALID_ID;
  4470.         struct NameInfo buff;
  4471.         struct List List = {0};
  4472.         struct DisplayMode DisplayMode = {0};
  4473.         struct ScreenModeRequester *req;
  4474.  
  4475.         NewList(&List);
  4476.         DisplayMode.dm_Node.ln_Name = GetMessage(MSG_NONE);
  4477.       DisplayMode.dm_PropertyFlags                     = DIPF_IS_WB;
  4478.         DisplayMode.dm_DimensionInfo.Header.StructID        = DTAG_DIMS;
  4479.         DisplayMode.dm_DimensionInfo.Header.DisplayID    = (ULONG)INVALID_ID;
  4480.         DisplayMode.dm_DimensionInfo.Header.SkipID         = TAG_SKIP;
  4481.       DisplayMode.dm_DimensionInfo.Header.Length        = sizeof(struct DimensionInfo);
  4482.       DisplayMode.dm_DimensionInfo.MaxDepth         = 24;
  4483.       DisplayMode.dm_DimensionInfo.MinRasterWidth   = 16;
  4484.       DisplayMode.dm_DimensionInfo.MinRasterHeight  = 16;
  4485.       DisplayMode.dm_DimensionInfo.MaxRasterWidth   = 2048;
  4486.       DisplayMode.dm_DimensionInfo.MaxRasterHeight  = 2048;
  4487.       DisplayMode.dm_DimensionInfo.Nominal.MinX     = 0;
  4488.       DisplayMode.dm_DimensionInfo.Nominal.MinY     = 0;
  4489.       DisplayMode.dm_DimensionInfo.Nominal.MaxX     = 640;
  4490.       DisplayMode.dm_DimensionInfo.Nominal.MaxY     = 200;
  4491.       DisplayMode.dm_DimensionInfo.TxtOScan         = DisplayMode.dm_DimensionInfo.Nominal;
  4492.       DisplayMode.dm_DimensionInfo.MaxOScan         = DisplayMode.dm_DimensionInfo.Nominal;
  4493.       DisplayMode.dm_DimensionInfo.VideoOScan       = DisplayMode.dm_DimensionInfo.Nominal;
  4494.       DisplayMode.dm_DimensionInfo.StdOScan         = DisplayMode.dm_DimensionInfo.Nominal;
  4495.         AddHead(&List,&(DisplayMode.dm_Node));
  4496.  
  4497.         id = NextDisplayInfo(id);
  4498.         while ((id != INVALID_ID) && (myid == INVALID_ID)) {
  4499.             if (GetDisplayInfoData(NULL,(UBYTE *)&buff,sizeof(struct NameInfo),DTAG_NAME,id)) {
  4500.                 if (!Stricmp(TempName,buff.Name)) {
  4501.                     myid = id;
  4502.                 }
  4503.             }
  4504.             id = NextDisplayInfo(id);
  4505.         }
  4506.         if (req = AllocAslRequest(ASL_ScreenModeRequest,NULL)) {
  4507.             if (AslRequestTags(req,
  4508.                                 ASLSM_Window, gh->Window,
  4509.                                 ASLSM_TitleText, Prompt,
  4510.                                 ASLSM_InitialDisplayID, myid,
  4511.                                 ((mg->ModeType == 2) || (mg->ModeType == 4)) ? ASLSM_CustomSMList : TAG_IGNORE,
  4512.                                     (ULONG)&List,
  4513.                                 (mg->ModeType > 2) ? ASLSM_PropertyFlags : TAG_IGNORE , NULL,
  4514.                                 (mg->ModeType > 2) ? ASLSM_PropertyMask : TAG_IGNORE, NULL,
  4515.                                 ASLSM_PositiveText,GetMessage(MSG_SELECT),
  4516.                                 ASLSM_IntuiMsgFunc, &(gh->RefreshHook),
  4517.                                 TAG_END)) {
  4518.                 if (GetDisplayInfoData(NULL,(UBYTE *)&buff,sizeof(struct NameInfo),DTAG_NAME,
  4519.                         req->sm_DisplayID)) {
  4520.                     strcpy(gh->TempFileName, buff.Name);
  4521.                 }
  4522.                 else {
  4523.                     strcpy(gh->TempFileName,"");
  4524.                 }
  4525.                 FreeAslRequest(req);
  4526.                 EnableWindow(gh);
  4527.                 return TRUE;
  4528.             }
  4529.             else {
  4530.                 FreeAslRequest(req);
  4531.                 EnableWindow(gh);
  4532.                 return FALSE;
  4533.             }
  4534.         }
  4535.         else {
  4536.             return FALSE;
  4537.         }
  4538.     }
  4539. }
  4540.  
  4541. void
  4542. DisableWindow(struct MPGuiHandle *gh) {
  4543.     InitRequester(&gh->Requestx);
  4544.     SetWindowPointer(gh->Window, WA_BusyPointer, TRUE, TAG_DONE);
  4545.     if (!gh->Disabled) {
  4546.         if (Request(&gh->Requestx,gh->Window)) {
  4547.             gh->Disabled = 1;
  4548.         }
  4549.     }
  4550.     else {
  4551.         ++gh->Disabled;
  4552.     }
  4553. }    
  4554.  
  4555. void
  4556. EnableWindow(struct MPGuiHandle *gh) {
  4557.     if (gh->Disabled) {
  4558.         --gh->Disabled;
  4559.     }
  4560.     if (!gh->Disabled) {
  4561.         SetWindowPointer(gh->Window,WA_Pointer, NULL, TAG_DONE);
  4562.         EndRequest(&gh->Requestx,gh->Window);
  4563.     }
  4564. }
  4565.  
  4566. ULONG
  4567. MyCallHookPkt(struct MPGuiHandle *gh,struct Hook *h,APTR a,APTR b) {
  4568.     ULONG ret;
  4569.     DisableWindow(gh);
  4570.     ret = CallHookPkt(h,a,b);
  4571.     EnableWindow(gh);
  4572.     return ret;
  4573. }
  4574.  
  4575. char
  4576. *GetMessage(UWORD message) {
  4577.     LONG   *l;
  4578.     UWORD  *w;
  4579.     STRPTR  builtIn;
  4580.  
  4581.    l = (LONG *)CatCompBlock;
  4582.  
  4583.     while (*l != message)  {
  4584.         w = (UWORD *)((ULONG)l + 4);
  4585.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  4586.     }
  4587.     builtIn = (STRPTR)((ULONG)l + 6);
  4588.     return(GetCatalogStr(Catalog,message,builtIn));
  4589. }
  4590.